package cn.com.cifi.mars.service.impl;

import cn.com.cifi.mars.bean.bo.PortalTodoBo;
import cn.com.cifi.mars.bean.bo.SysLogBO;
import cn.com.cifi.mars.bean.dto.MonitorConfigDetailDto;
import cn.com.cifi.mars.bean.dto.ProjectByStagesDto;
import cn.com.cifi.mars.bean.vo.monitoringConsole.*;
import cn.com.cifi.mars.common.exception.MsgException;
import cn.com.cifi.mars.constant.*;
import cn.com.cifi.mars.entity.*;
import cn.com.cifi.mars.entity.common.IdmUser;
import cn.com.cifi.mars.entity.common.ProjectByStages;
import cn.com.cifi.mars.entity.common.SysUserRole;
import cn.com.cifi.mars.mapper.mars.*;
import cn.com.cifi.mars.service.CommonService;
import cn.com.cifi.mars.service.IdmUserService;
import cn.com.cifi.mars.service.MonitoringConsoleService;
import cn.com.cifi.mars.service.SysLogService;
import cn.com.cifi.mars.util.*;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.math.RoundingMode;
import java.time.LocalDateTime;
import java.util.*;
import java.util.Map.Entry;
import java.util.stream.Collectors;
/**
 * 监控台
 * @author Li
 *
 */
@Slf4j
@Service
public class MonitoringConsoleServiceImpl implements MonitoringConsoleService {
	
	/**
	 * 数据中台地址
	 */
	@Value("${data_middle_ground_url}")
	private String data_middle_ground_url;
	
	/**
	 * 指标-储汇总
	 */
	@Value("${store_url}")
	private String store_url;

	/**
	 * 储-明细
	 */
	@Value("${storeItem_url}")
	private String storeItem_url;
	/**
	 * 指标-产
	 */
	@Value("${produce_url}")
	private String produce_url;
	
	/**
	 * 产-明细
	 */
	@Value("${produceItem_url}")
	private String produceItem_url;
	
	/**
	 * 指标-供
	 */
	@Value("${supply_url}")
	private String supply_url;
	
	/**
	 * 供-明细
	 */
	@Value("${supplyItem_url}")
	private String supplyItem_url;
	
	/**
	 * 指标-销
	 */
	@Value("${sale_url}")
	private String sale_url;
	
	/**
	 * 销-明细
	 */
	@Value("${saleItem_url}")
	private String saleItem_url;
	
	/**
	 * 指标-存
	 */
	@Value("${stock_url}")
	private String stock_url;
	
	/**
	 * 存-明细
	 */
	@Value("${stockItem_url}")
	private String stockItem_url;
	
	/**
	 * 指标-结
	 */
	@Value("${statement_url}")
	private String statement_url;
	/**
	 * 结-明细
	 */
	@Value("${statementItem_url}")
	private String statementItem_url;
	/**
	 * 指标-货值
	 */
	@Value("${storeReport_url}")
	private String storeReport_url;
	
	/**
	 * 存-业态存销比
	 */
	@Value("${storeSaleRate_url}")
	private String storeSaleRate_url;
	
	/**
	 * 数据中心key
	 */
	@Value("${data_api_key}")
	private String data_api_key;
	
	/**
	 * 数据中心value
	 */
	@Value("${data_api_value}")
	private String data_api_value;
	
	/**
	 * 门户待办手机端地址
	 */
	@Value("${mobileUrl}")
	private String mobileUrl;
	
	/**
	 * 门户待办pc端地址
	 */
	@Value("${pcUrl}")
	private String pcUrl;
	
	@Autowired
	private SysLogService sysLogService;
	@Autowired
	private ProjectByStagesMapper projectByStagesMapper;
	@Autowired
	private MonitorConfigDetailMapper monitorConfigDetailMapper;
	@Autowired
	private IdmUserMapper idmUserMapper;
	@Autowired
	private SysUserRoleMapper sysUserRoleMapper;
	@Autowired
	private IdmPositionMapper idmPositionMapper;
	@Autowired
	private SysPositionGroupAuthorizeMapper sysPositionGroupAuthorizeMapper;
	@Autowired
	private CommonService commonService;
	@Autowired
	private IdmUserService idmUserService;
	@Autowired
	private MonitorWarningMapper monitorWarningMapper;
	@Autowired
	private MonitorWarningConfigMapper monitorWarningConfigMapper;
	@Autowired
	private MonitorWarningLogMapper monitorWarningLogMapper;
	@Autowired
	private MonitorWarningPortalMapper monitorWarningPortalMapper;
	@Autowired
	private MonitorWarningQuotaMapper monitorWarningQuotaMapper;
	@Autowired
    private SupervisoryConsoleReturnDetailMapper supervisoryConsoleReturnDetailMapper;

	/**
	 * 调用数据中台储-汇总接口
	 * @param orgId 组织机构id
	 * @param reportDate 查询截止日期
	 */
	public StoreVo getPrcFactSmdOrg(String orgId, String reportDate,List<MonitorConfigDetailDto>monitorConfigDetailList) {
		
		//静态储备周期详情
		List<MonitorConfigDetailDto>agList=monitorConfigDetailList.stream()
				.filter(x->x.getTargetCode().equals(TargetNameEnum.A.getKey())).collect(Collectors.toList());
		//动态储备周期监控详情
		List<MonitorConfigDetailDto>bgList=monitorConfigDetailList.stream()
				.filter(x->x.getTargetCode().equals(TargetNameEnum.B.getKey())).collect(Collectors.toList());
		
		StoreVo vo=new StoreVo();
		//日志路径
		String logUrl="MonitoringConsoleServiceImpl/getPrcFactSmdOrg";
		//标题
		String title="获取储-汇总接口";
		
		BasicAuthClient bac = new BasicAuthClient();
		String api =store_url+orgId+","+reportDate;
		//拼接地址
		String url = data_middle_ground_url+api;
		String result = bac.getData(url, data_api_key, data_api_value);
		log.info("###储-汇总接口 地址： "+url);
		log.info("###储-汇总接口 返回数据："+result);
		if(StrUtils.isNotEmpty(result)) {
			JSONObject jsonObject=JSONObject.parseObject(result);
			if(jsonObject!=null) {
				int retCode=jsonObject.getInteger("retCode");
				if(retCode==Constants.ZERO) {
					JSONArray retData=jsonObject.getJSONArray("retData");	
					if(retData != null) {
						for (int i = 0; i < retData.size(); i++) {
							JSONObject retDataObj=retData.getJSONObject(i);
							//土储货值(香港口径)
							BigDecimal soilStoreValueHk=retDataObj.getBigDecimal("soilStoreValueHk");
							//土储货值(投资口径)
							BigDecimal soilStoreValueInv=retDataObj.getBigDecimal("soilStoreValueInv");
							//动态储备周期
							Double dynamicResvCycle=retDataObj.getDouble("dynamicResvCycle");
							//静态储备周期
							Double staticResvCycle=retDataObj.getDouble("staticResvCycle");
							//已售未结货值(亿元)
							BigDecimal soldNotSettle=retDataObj.getBigDecimal("soldNotSettle");
							
							//是否满足预警条件
							String agStatus=Constants.NONE;
							String bgStatus=Constants.NONE;
							vo.setStaticResvCycle("");
							if(staticResvCycle!=null) {
								agStatus=getStatus(agList, staticResvCycle);
								vo.setStaticResvCycle(staticResvCycle.toString());
							}
							vo.setDynamicResvCycle("");
							if(dynamicResvCycle!=null) {
								bgStatus=getStatus(bgList, dynamicResvCycle);
								vo.setDynamicResvCycle(dynamicResvCycle.toString());
							}
							vo.setSoilStoreValueHk(soilStoreValueHk.toString());
							vo.setSoilStoreValueInv(soilStoreValueInv.toString());
							vo.setSoldNotSettle(soldNotSettle.toString());
							//(warning-预警标准-红色,remind-提醒标准-黄色,health-健康标准-绿色,none-没有)
							vo.setStaticResvCycle_status(agStatus);
							vo.setDynamicResvCycle_status(bgStatus);
						}
					}
					return vo;
				}else {
					//获取失败
					saveLog("获取储-汇总接口失败",logUrl,title,Constants.MONITORING_CONSOLE);
				}
			}
		} else {
			log.info("获取储-汇总接口失败");
			saveLog("获取储-汇总接口失败",logUrl,title,Constants.MONITORING_CONSOLE);
		}
		
		return vo;
	}

	
	/**
	 * 调用数据中台储-明细接口
	 * @param orgId 组织机构id
	 * @param reportDate 查询截止日期
	 */
	public StoreItemVo getPrcFactSmdPrntOrg(String orgId, String reportDate,List<MonitorConfigDetailDto> monitorConfigDetailDtoList,String hrOrgTypeId) {
		//切换下级类型
		hrOrgTypeId=getOrgNextType(hrOrgTypeId);
		StoreItemVo vo=new StoreItemVo();
		//储汇总
		StoreVo storeVo=new StoreVo();
		//日志路径
		String logUrl="MonitoringConsoleServiceImpl/getPrcFactSmdPrntOrg";
		//标题
		String title="获取储-明细接口";
		
		BasicAuthClient bac = new BasicAuthClient();
		String api =storeItem_url+orgId+","+reportDate;
		//拼接地址
		String url = data_middle_ground_url+api;
		String result = bac.getData(url, data_api_key, data_api_value);
		log.info("###储-明细接口 地址： "+url);
		log.info("###储-明细接口 返回数据："+result);
		JSONObject jsonObject=JSONObject.parseObject(result);
		if(jsonObject!=null) {
			int retCode=jsonObject.getInteger("retCode");
			if(retCode==Constants.ZERO) {
				//静态储备周期
				List<OrgRoundVo>staticList=new ArrayList<>();
				//动态储备周期
				List<OrgRoundVo>dynamicList=new ArrayList<>();
				//土储货值投资口径(亿元)
				List<OrgRoundVo>investmentList=new ArrayList<>();
				//土储货值香港口径(亿元)
				List<OrgRoundVo>hongKongList=new ArrayList<>();
				//已售未结货值(亿元)
				List<OrgRoundVo>unsoldList=new ArrayList<>();
				
				//静态储备周期详情
				List<MonitorConfigDetailDto>aList=monitorConfigDetailDtoList.stream()
						.filter(x->x.getTargetCode().equals(TargetNameEnum.A.getKey())).collect(Collectors.toList());
				//动态储备周期监控详情
				List<MonitorConfigDetailDto>bList=monitorConfigDetailDtoList.stream()
						.filter(x->x.getTargetCode().equals(TargetNameEnum.B.getKey())).collect(Collectors.toList());
				
				//汇总组织机构信息和圆点
				List<OrgRoundVo>summaryOrgList=new ArrayList<>();;
				
				//获取成功
				JSONArray retData=jsonObject.getJSONArray("retData");
				if(retData != null) {
					if(retData != null && retData.size() > 0) {
						for (int i = 0; i < retData.size(); i++) {
							JSONObject retDataObj=retData.getJSONObject(i);
							//土储货值(香港口径)
							Double soilStoreValueHk=retDataObj.getDouble("soilStoreValueHk");
							//土储货值(投资口径)
							Double soilStoreValueInv=retDataObj.getDouble("soilStoreValueInv");
							//动态储备周期
							Double dynamicResvCycle=retDataObj.getDouble("dynamicResvCycle");
							//静态储备周期
							Double staticResvCycle=retDataObj.getDouble("staticResvCycle");
							//已售未结货值(亿元)
							Double soldNotSettle=retDataObj.getDouble("soldNotSettle");
							//组织机构id
							String orgId1=retDataObj.getString("orgId");
							//组织机构名称
							String orgName=retDataObj.getString("orgName");
							
							
							//静态储备周期
							OrgRoundVo staticVo=getOrgRoundStatus(orgName, aList, orgId1, staticResvCycle, hrOrgTypeId);
							//动态储备周期
							OrgRoundVo dynamicVo=getOrgRoundStatus(orgName, bList, orgId1, dynamicResvCycle, hrOrgTypeId);
							//土储货值投资口径(亿元)
							OrgRoundVo investmentVo=getOrgRoundNoStatus(orgName, orgId1, soilStoreValueInv, hrOrgTypeId);
							//土储货值香港口径(亿元)
							OrgRoundVo hongKongVo=getOrgRoundNoStatus(orgName, orgId1, soilStoreValueHk, hrOrgTypeId);
							//已售未结货值(亿元)
							OrgRoundVo unsoldVo=getOrgRoundNoStatus(orgName, orgId1, soldNotSettle, hrOrgTypeId);

							if(staticVo.getResourceStatus().equals(Constants.WARNING) && dynamicVo.getResourceStatus().equals(Constants.WARNING)) {
								//2个条件都存在把组织机构放进去
								OrgRoundVo orgVo=getOrgRoundWarning(orgName, orgId1, hrOrgTypeId);
								summaryOrgList.add(orgVo);
							}
							
							//最后把vo放到list里面
							staticList.add(staticVo);
							dynamicList.add(dynamicVo);
							investmentList.add(investmentVo);
							hongKongList.add(hongKongVo);
							unsoldList.add(unsoldVo);
						}
					}
				}
				
				
				//预警红黄绿
				StrUtils.compareOrder(staticList);
				StrUtils.compareOrder(dynamicList);
				
				//亿元 从大到小
				investmentList.sort((OrgRoundVo o1, OrgRoundVo o2)->o2.getQuotaVal().compareTo(o1.getQuotaVal()));
				hongKongList.sort((OrgRoundVo o1, OrgRoundVo o2)->o2.getQuotaVal().compareTo(o1.getQuotaVal()));
				unsoldList.sort((OrgRoundVo o1, OrgRoundVo o2)->o2.getQuotaVal().compareTo(o1.getQuotaVal()));
				//把都符合条件的组织机构信息都放进去
				storeVo.setOrgRoundList(summaryOrgList);
				
				//把list放到大的vo里面
				vo.setStaticList(staticList);
				vo.setDynamicList(dynamicList);
				vo.setInvestmentList(investmentList);
				vo.setHongKongList(hongKongList);
				vo.setUnsoldList(unsoldList);
				vo.setStoreVo(storeVo);
			}else {
				//获取失败
				saveLog("获取储-明细接口失败",logUrl,title,Constants.MONITORING_CONSOLE);
			}
		}else {
			log.info("获取储-明细接口失败");
			saveLog("获取储-明细接口失败",logUrl,title,Constants.MONITORING_CONSOLE);
		}
		return vo;
	}


	/**
	 * 货值监控
	 */
	@Override
	public PriceValueVo getValueMonitoring(String orgId, String reportDate) {
		return getDataStoreReport(orgId, reportDate);
	}


	/**
	 * 核心指标监控
	 */
	@Override
	public CoreQuotaVo getCoreQuotaStore(String orgId, String reportDate,String hrOrgTypeId) {
		CoreQuotaVo vo=new CoreQuotaVo();
		
		List<MonitorConfigDetailDto> monitorConfigDetailDtoList=getDetailByOrgId(orgId,hrOrgTypeId); 
		//静态储备周期
		String staticResvCycle="";
		//动态储备周期
		String dynamicResvCycle="";
		//首开项目开销比
		String firstOpenOvhdRateList="";
		//续销项目在途比
		String renewalInTransitRateList="";
		//库存去化率
		String stockRemovalRateList="";
		//长期库存去化率
		String stockRemovalRatelongtime="";
		//存销比
		String storeSaleRate="";
		//长期库存
		String storeLongTime="";
		//长期库存存销比
		String storeSaleRatelongtime="";
		//结转去化率  1-6月取上半年 7-12取下半年
		String statementRate="";
		//回款率
        String returnRate = "";
		//截取月份
		String month=reportDate.substring(4,6);
		
		if(CollectionUtils.isNotEmpty(monitorConfigDetailDtoList)) {
			for (MonitorConfigDetailDto md : monitorConfigDetailDtoList) {
				//监控设置明细类型(1健康标准2提醒标准3预警标准)
				if(md.getMonitorType().equals(Constants.THREE+"")) {
					//只要预警标准
					//静态储备周期
					if(md.getTargetCode().equals(TargetNameEnum.A.getKey())) {
						staticResvCycle=OperatorUtils.splicingOperator(md,TargetNameEnum.A.getValue());
					}
					//动态储备周期
					if(md.getTargetCode().equals(TargetNameEnum.B.getKey())) {
						dynamicResvCycle=OperatorUtils.splicingOperator(md,TargetNameEnum.B.getValue());
					}
					//首开项目开销比
					if(md.getTargetCode().equals(TargetNameEnum.C.getKey())) {
						firstOpenOvhdRateList=OperatorUtils.splicingOperator(md,TargetNameEnum.C.getValue());
					}
					//续销项目在途比
					if(md.getTargetCode().equals(TargetNameEnum.D.getKey())) {
						renewalInTransitRateList=OperatorUtils.splicingOperator(md,TargetNameEnum.D.getValue());
					}
					//库存去化率
					if(md.getTargetCode().equals(TargetNameEnum.I.getKey())) {
						stockRemovalRateList=OperatorUtils.splicingOperator(md,TargetNameEnum.I.getValue());
					}
					//长期库存去化率
					if(md.getTargetCode().equals(TargetNameEnum.J.getKey())) {
						stockRemovalRatelongtime=OperatorUtils.splicingOperator(md,TargetNameEnum.J.getValue());
					}
					//存销比
					if(md.getTargetCode().equals(TargetNameEnum.L.getKey())) {
						storeSaleRate=OperatorUtils.splicingOperator(md,TargetNameEnum.L.getValue());
					}
					//长期库存占比
					if(md.getTargetCode().equals(TargetNameEnum.M.getKey())) {
						storeLongTime=OperatorUtils.splicingOperator(md,TargetNameEnum.M.getValue());
					}
					//长期库存存销比
					if(md.getTargetCode().equals(TargetNameEnum.O.getKey())) {
						storeSaleRatelongtime=OperatorUtils.splicingOperator(md,TargetNameEnum.O.getValue());
					}
					//结转去化率  1-6月取上半年 
					if(md.getTargetCode().equals(TargetNameEnum.Q.getKey())) {
						if(Integer.parseInt(month)<=Constants.SIX) {
							statementRate=OperatorUtils.splicingOperator(md,TargetNameEnum.Q.getValue());
						}
					}
					//结转去化率   7-12取下半年
					if(md.getTargetCode().equals(TargetNameEnum.R.getKey())) {
						if(Integer.parseInt(month)>=Constants.SEVEN) {
							statementRate=OperatorUtils.splicingOperator(md,TargetNameEnum.R.getValue());
						}
					}
					 //回款比率
                    if (md.getTargetCode().equals(TargetNameEnum.S.getKey())) {
                        returnRate = OperatorUtils.splicingOperator(md, TargetNameEnum.S.getValue());
                    }
				}
			}
		}

		//声明一个大的map存放组织和数量
		Map<String,Integer>map=new HashMap<>();
		
		//储-明细接口
		StoreItemVo storeItemVo=getPrcFactSmdPrntOrg(orgId, reportDate,monitorConfigDetailDtoList,hrOrgTypeId);
		//储-汇总接口
		StoreVo storeVo=getPrcFactSmdOrg(orgId,reportDate,monitorConfigDetailDtoList);
		storeVo.setEarlyWarning(staticResvCycle+ConditionTypeEnum.TWO.getValue()+dynamicResvCycle);
		storeVo.setOrgRoundList(storeItemVo==null?null:(storeItemVo.getStoreVo()==null?null:storeItemVo.getStoreVo().getOrgRoundList()));
		//存放组织机构数量
		getOrgNum(map, storeVo.getOrgRoundList());
		
		
		//产-明细接口
		ProduceItemVo produceItemVo=getDataProduceItem(orgId, reportDate,monitorConfigDetailDtoList,hrOrgTypeId);
		//产-汇总接口
		ProduceVo produceVo=getDataProduce(orgId, reportDate,monitorConfigDetailDtoList);
		produceVo.setEarlyWarning(firstOpenOvhdRateList+ConditionTypeEnum.TWO.getValue()+renewalInTransitRateList);
		produceVo.setOrgRoundList(produceItemVo.getProduceVo().getOrgRoundList());
		//存放组织机构数量
		getOrgNum(map, produceVo.getOrgRoundList());
		//供汇总
		SupplyVo supplyVo=getDataSupply(orgId, reportDate,monitorConfigDetailDtoList);
		
		
		//销-明细接口
		SaleItemVo saleItemVo=getDataSaleItem(orgId, reportDate,monitorConfigDetailDtoList,hrOrgTypeId);
		//销-汇总接口
		SaleVo saleVo=getDataSale(orgId, reportDate,monitorConfigDetailDtoList);
		saleVo.setEarlyWarning(stockRemovalRateList+ConditionTypeEnum.TWO.getValue()+stockRemovalRatelongtime);
		saleVo.setOrgRoundList(saleItemVo.getSaleVo().getOrgRoundList());
		//存放组织机构数量
		getOrgNum(map, saleVo.getOrgRoundList());
		
		
		//TODO:调用数据中台回-明细接口
        ReturnItemVo returnItemVo = getReturnItem(orgId, reportDate, monitorConfigDetailDtoList, hrOrgTypeId);
        //回汇总
        ReturnVo returnVo = getDataReturn(orgId, reportDate, monitorConfigDetailDtoList);
        //TODO:预警信息
        returnVo.setEarlyWarning(returnRate);
        //信息和圆点
        returnVo.setOrgRound(returnItemVo.getReturnVo().getOrgRound());
        //存放组织机构数量
        getOrgNum(map, returnVo.getOrgRound());
		
		//存-明细接口
		StockItemVo stockItemVo=getDataStockItem(orgId, reportDate,monitorConfigDetailDtoList,hrOrgTypeId);
		//存-汇总接口
	    StockVo stockVo=getDataStock(orgId, reportDate,monitorConfigDetailDtoList);
	    stockVo.setEarlyWarning(storeSaleRate
	    		+ConditionTypeEnum.TWO.getValue()
	    		+storeLongTime
	    		+ConditionTypeEnum.TWO.getValue()
	    		+storeSaleRatelongtime);
	    
	    if(stockItemVo.getStockVo() != null && CollectionUtils.isNotEmpty(stockItemVo.getStockVo().getOrgRoundList())) {
	    	stockVo.setOrgRoundList(stockItemVo.getStockVo().getOrgRoundList());
		}
	    //存放组织机构数量
	  	getOrgNum(map, stockVo.getOrgRoundList());
	    
	    //结-明细接口
	    StatementItemVo statementItemVo=getDataStatementItem(orgId, reportDate,monitorConfigDetailDtoList,hrOrgTypeId);
		//结-汇总接口
		StatementVo statementVo=getDataStatement(orgId, reportDate,monitorConfigDetailDtoList);
		statementVo.setEarlyWarning(statementRate);
		statementVo.setOrgRoundList(statementItemVo.getStatementVo()==null? statementVo.getOrgRoundList():statementItemVo.getStatementVo().getOrgRoundList());
		//存放组织机构数量
	  	getOrgNum(map, statementVo.getOrgRoundList());
		
		//三个及以上维度存在问题区域/城市公司
		List<String> existingProblems=new ArrayList<>();
		if(map!=null) {
			for (Entry<String, Integer> mp : map.entrySet()) {
				//大于等于3个组织才放进去
				if(mp.getValue()>=Constants.THREE) {
					existingProblems.add(mp.getKey());
				}
			}
		}
		vo.setStoreVo(storeVo);
		vo.setProduceVo(produceVo);
		vo.setSupplyVo(supplyVo);
		vo.setSaleVo(saleVo);
		vo.setStockVo(stockVo);
		vo.setStatementVo(statementVo);
		vo.setExistingProblems(existingProblems);
		vo.setReturnVo(returnVo);
		return vo;
	}


	/**
	 * 监控指标-储明细
	 */
	@Override
	public StoreItemVo getStoreItem(String orgId, String reportDate,List<MonitorConfigDetailDto> monitorConfigDetailDtoList,String hrOrgTypeId) {
		//调用数据中台储-明细接口
		StoreItemVo vo=getPrcFactSmdPrntOrg(orgId, reportDate,monitorConfigDetailDtoList,hrOrgTypeId);
		//调用数据中台储-汇总接口
		StoreVo storeVo=getPrcFactSmdOrg(orgId,reportDate,monitorConfigDetailDtoList);
		vo.setStoreVo(storeVo);
		return vo;
	}

	
	/**
	 * 监控指标-产明细
	 */
	@Override
	public ProduceItemVo getProduceItem(String orgId, String reportDate,List<MonitorConfigDetailDto> monitorConfigDetailDtoList,String hrOrgTypeId) {
		ProduceItemVo vo=getDataProduceItem(orgId, reportDate, monitorConfigDetailDtoList,hrOrgTypeId);
		//调用数据中台产-汇总接口
		ProduceVo produceVo=getDataProduce(orgId,reportDate,monitorConfigDetailDtoList);
		vo.setProduceVo(produceVo);
		return vo;
	}

	/**
	 * 监控指标-供明细
	 */
	@Override
	public SupplyItemVo getSupplyItem(String orgId, String reportDate,List<MonitorConfigDetailDto> monitorConfigDetailDtoList,String hrOrgTypeId) {
		SupplyItemVo vo=getDataSupplyItem(orgId, reportDate, monitorConfigDetailDtoList,hrOrgTypeId);
		SupplyVo supplyVo=getDataSupply(orgId, reportDate, monitorConfigDetailDtoList);
		vo.setSupplyVo(supplyVo);
		return vo;
	}

	/**
	 * 监控指标-销明细
	 */
	@Override
	public SaleItemVo getSaleItem(String orgId, String reportDate,List<MonitorConfigDetailDto> monitorConfigDetailDtoList,String hrOrgTypeId) {
		SaleItemVo vo=getDataSaleItem(orgId, reportDate,monitorConfigDetailDtoList,hrOrgTypeId);
		SaleVo saleVo=getDataSale(orgId, reportDate, monitorConfigDetailDtoList);
		vo.setSaleVo(saleVo);
		return vo;
	}

	/**
	 * 监控指标-存明细
	 */
	@Override
	public StockItemVo getStockItem(String orgId, String reportDate,List<MonitorConfigDetailDto> monitorConfigDetailDtoList,String hrOrgTypeId) {
		StockItemVo vo=getDataStockItem(orgId, reportDate,monitorConfigDetailDtoList,hrOrgTypeId);
		StockVo stockVo=getDataStock(orgId, reportDate, monitorConfigDetailDtoList);
		vo.setStockVo(stockVo);
		return vo;
	}

	/**
	 * 监控指标-结明细
	 */
	@Override
	public StatementItemVo getStatementItem(String orgId, String reportDate,List<MonitorConfigDetailDto> monitorConfigDetailDtoList,String hrOrgTypeId) {
		StatementItemVo vo=getDataStatementItem(orgId, reportDate,monitorConfigDetailDtoList,hrOrgTypeId);
		StatementVo statementVo=getDataStatement(orgId, reportDate, monitorConfigDetailDtoList);
		vo.setStatementVo(statementVo);
		return vo;
	}
	
	 /**
     * 监控指标-回明细
     */
    @Override
    public ReturnItemVo getReturnItem(String orgId, String reportDate, List<MonitorConfigDetailDto> monitorConfigDetailDtoList, String hrOrgTypeId) {
        ReturnItemVo vo = getDataReturnItem(orgId, reportDate, monitorConfigDetailDtoList, hrOrgTypeId);
        ReturnVo returnVo = getDataReturn(orgId, reportDate, monitorConfigDetailDtoList);
        vo.setReturnVo(returnVo);
        return vo;

    }
	               
	
	/**
	 * 添加日志
	 * @param module
	 * @param title
	 * @param content
	 */
	private void saveLog(String content,String url,String title,String module) {
        SysLogBO bo = new SysLogBO();
        bo.setEvent(LogEventEnum.BROWSE);
        bo.setSource(LogSrcEnum.SYS);
        String hostAddr =WebUtils.getLocalIP();
        String hostName = WebUtils.getHostName();
        bo.setIp(hostAddr);
        //模块
        bo.setModule(module);
        bo.setTitle(title);
        bo.setContent(content+" 本地机器名:"+hostName);
        bo.setType(LogTypeEnum.ONE.getKey());
        bo.setIsSuccess(IsSuccessEnum.SUCCESS.getKey());
        bo.setUrl(url);
        sysLogService.add(bo,Constants.SYS);
    }
	
	
	/**
	 * 判断标准属于哪一个
	 * @param list
	 * @param value
	 */
	public static String getStatus(List<MonitorConfigDetailDto>list,double value) {
		if(CollectionUtils.isNotEmpty(list)) {
			for (MonitorConfigDetailDto md : list) {
				boolean flag=OperatorUtils.getDoesItMatch(md, value);
				//圆点状态(warning-预警标准-红色,remind-提醒标准-黄色,health-健康标准-绿色)
				//1健康标准
				if(md.getMonitorType().equals(Constants.ONE+"")) {
					if(flag) {
						//health
						return Constants.HEALTH;
					}
				}
				//2提醒标准
				if(md.getMonitorType().equals(Constants.TWO+"")) {
					if(flag) {
						//remind
						return Constants.REMIND;
					}
				}
				//3预警标准
				if(md.getMonitorType().equals(Constants.THREE+"")) {
					if(flag) {
						//warning
						return Constants.WARNING;
					}
				}
			}
		}
		//none没有状态
		return Constants.NONE;
	}
	

	/**
	 * 调用数据中台-货值
	 * @param orgId 组织机构id
	 * @param reportDate 查询截止日期
	 */
	public PriceValueVo getDataStoreReport(String orgId, String reportDate) {
		PriceValueVo vo=new PriceValueVo();
		//日志路径
		String logUrl="MonitoringConsoleServiceImpl/getDataStoreReport";
		//标题
		String title="数据中台-货值";
		BasicAuthClient bac = new BasicAuthClient();
		String api =storeReport_url+orgId+","+reportDate;
		//拼接地址
		String url = data_middle_ground_url+api;
		String result = bac.getData(url, data_api_key, data_api_value);
		JSONObject jsonObject=JSONObject.parseObject(result);
		if(jsonObject!=null) {
			int retCode=jsonObject.getInteger("retCode");
			if(retCode==Constants.ZERO) {
				JSONArray retData=jsonObject.getJSONArray("retData");	
				if(retData != null) {
					for (int i = 0; i < retData.size(); i++) {
						JSONObject retDataObj=retData.getJSONObject(i);
						
						BigDecimal continueCount=retDataObj.getBigDecimal("continueCount");
						BigDecimal stagePrice=retDataObj.getBigDecimal("stagePrice");
						BigDecimal soilStoreEquityHk=retDataObj.getBigDecimal("soilStoreEquityHk");
						BigDecimal soilStoreEquityInv=retDataObj.getBigDecimal("soilStoreEquityInv");
						int projectCount=retDataObj.getInteger("projectCount");
						BigDecimal soilStoreEquityRateInv=retDataObj.getBigDecimal("soilStoreEquityRateInv");
						BigDecimal totalPrice=retDataObj.getBigDecimal("totalPrice");
						BigDecimal stageRate=retDataObj.getBigDecimal("stageRate");
						BigDecimal soilStoreInv=retDataObj.getBigDecimal("soilStoreInv");
						BigDecimal soilStoreHk=retDataObj.getBigDecimal("soilStoreHk");
						BigDecimal stockEquityPrice=retDataObj.getBigDecimal("stockEquityPrice");
						BigDecimal saledPrice=retDataObj.getBigDecimal("saledPrice");
						BigDecimal stockPrice=retDataObj.getBigDecimal("stockPrice");
						BigDecimal firstOpen=retDataObj.getBigDecimal("firstOpen");
						BigDecimal planEquityRate=retDataObj.getBigDecimal("planEquityRate");
						BigDecimal equityPrice=retDataObj.getBigDecimal("equityPrice");
						BigDecimal soilStoreEquityRateHk=retDataObj.getBigDecimal("soilStoreEquityRateHk");
						BigDecimal stageSaledPrice=retDataObj.getBigDecimal("stageSaledPrice");
						BigDecimal stockEquityPriceReat=retDataObj.getBigDecimal("stockEquityPriceReat");
						BigDecimal planPrice=retDataObj.getBigDecimal("planPrice");
						BigDecimal planEquityPrice=retDataObj.getBigDecimal("planEquityPrice");

						//项目总数(个)
						vo.setProjectCount(projectCount+"");
						//首开项目(个)
						vo.setFirstOpen(firstOpen.toString());
						//续销项目(个)
						vo.setContinueCount(continueCount.toString());
						//总货值(亿元)
						vo.setTotalPrice(totalPrice.toString());
						//权益总货值(亿元)
						vo.setEquityPrice(equityPrice.toString());
						//阶段自持货值(亿元)
						vo.setStagePrice(stagePrice.toString());
						//已售货值(亿元)
						vo.setSaledPrice(saledPrice.toString());
						//权益已售货值(亿元)
						vo.setStageSaledPrice(stageSaledPrice.toString());
						//权益比例(已售货值)(百分比)
						vo.setStageRate(stageRate.toString());
						//存货货值(亿元)
						vo.setStockPrice(stockPrice.toString());
						//权益存货货值(亿元)
						vo.setStockEquityPrice(stockEquityPrice.toString());
						//权益比例(存货货值)(百分比)
						vo.setStockEquityPriceReat(stockEquityPriceReat.toString());
						//规划货值(亿元)
						vo.setPlanPrice(planPrice.toString());
						//权益规划货值(亿元)
						vo.setPlanEquityPrice(planEquityPrice.toString());
						//权益比例(规划货值)(百分比)
						vo.setPlanEquityRate(planEquityRate.toString());
						//土储货值(香港口径)(亿元)
						vo.setSoilStoreHk(soilStoreHk.toString());
						//权益土储货值(香港口径)(亿元)
						vo.setSoilStoreEquityHk(soilStoreEquityHk.toString());
						//权益比例(土储货值-香港口径)(百分比)
						vo.setSoilStoreEquityRateHk(soilStoreEquityRateHk.toString());
						//土储货值(投资口径)(亿元)
						vo.setSoilStoreInv(soilStoreInv.toString());
						//权益土储货值(投资口径)(亿元)
						vo.setSoilStoreEquityInv(soilStoreEquityInv.toString());
						//权益比例(土储货值-投资口径)(百分比)
						vo.setSoilStoreEquityRateInv(soilStoreEquityRateInv.toString());
					}
				}
				return vo;
			}else {
				log.info("获取货值接口失败");
				saveLog("获取货值接口失败",logUrl,title,Constants.MONITORING_CONSOLE);
			}
		}else {
			log.info("获取货值接口失败");
			saveLog("获取货值接口失败",logUrl,title,Constants.MONITORING_CONSOLE);
		}
		return vo;
	}



	/**
	 * 根据组织机构id和类型查询监控配置和详情
	 * @return
	 */
	@Override
	public List<MonitorConfigDetailDto> getDetailByOrgId(String orgId,String hrOrgTypeId) {
		//查询旭辉集团的监控配置详情
		List<MonitorConfigDetailDto>groupList=monitorConfigDetailMapper.selectDetailByOrgId(IsDeleteEnum.NO.getKey()+"",Constants.XUHUI_GROUP);

		if(hrOrgTypeId.equals(HrOrgTypeEunm.ORG_11.getKey())) {
			//旭辉集团
		}else {
			//根据组织机构id查询全路径id
			ProjectByStages projectByStages=projectByStagesMapper.selectByPrimaryKey(orgId);
			if(null==projectByStages) {
				throw new MsgException(CodeEnum.SYS_REGION_ID_ERROR);
			}
			List<String>orgdepids=new ArrayList<>();
			String [] orgnofullpath=projectByStages.getOrgnofullpath().split("-");
			for (String str : orgnofullpath) {
				orgdepids.add(str);
			}
			//查询该组织机构的区域id
			orgId=projectByStagesMapper.selectHrOrgdepId(orgdepids, HrOrgTypeEunm.ORG_20.getKey());
			List<MonitorConfigDetailDto> list = monitorConfigDetailMapper.selectDetailByOrgId(IsDeleteEnum.NO.getKey()+"", orgId);
			//如果区域为空 返回集团
			if(CollectionUtils.isEmpty(list)) {
				return groupList;
			}else {
				return list;
			}
		}
		return groupList;
	}

	

	/**
	 * 调用数据中台产-汇总接口
	 * @param orgId 组织机构id
	 * @param reportDate 查询截止日期
	 */
	public ProduceVo getDataProduce(String orgId, String reportDate,List<MonitorConfigDetailDto> monitorConfigDetailDtoList) {
		//首开项目开销比配置详情
		List<MonitorConfigDetailDto>cList=monitorConfigDetailDtoList.stream()
				.filter(x->x.getTargetCode().equals(TargetNameEnum.C.getKey())).collect(Collectors.toList());
		//续销项目在途比配置详情
		List<MonitorConfigDetailDto>dList=monitorConfigDetailDtoList.stream()
				.filter(x->x.getTargetCode().equals(TargetNameEnum.D.getKey())).collect(Collectors.toList());
		
		ProduceVo vo=new ProduceVo();
		//日志路径
		String logUrl="MonitoringConsoleServiceImpl/getDataProduce";
		//标题
		String title="获取产-汇总接口";
		BasicAuthClient bac = new BasicAuthClient();
		String api =produce_url+orgId+","+reportDate;
		//拼接地址
		String url = data_middle_ground_url+api;
		String result = bac.getData(url, data_api_key, data_api_value);
		log.info("###产-汇总接口 地址： "+url);
		log.info("###产-汇总接口 返回数据："+result);
		if(StrUtils.isNotEmpty(result)) {
			JSONObject jsonObject=JSONObject.parseObject(result);
			if(jsonObject!=null) {
				int retCode=jsonObject.getInteger("retCode");
				if(retCode==Constants.ZERO) {
					JSONArray retData=jsonObject.getJSONArray("retData");	
					if(retData != null) {
						for (int i = 0; i < retData.size(); i++) {
							JSONObject retDataObj=retData.getJSONObject(i);
							//首开项目开销比
							Double firstOpenOvhdRate=retDataObj.getDouble("firstOpenOvhdRate");
							//续销项目在途比
							Double renewalInTransitRate=retDataObj.getDouble("renewalInTransitRate");
							//在途资源(亿元)
							BigDecimal inTransitResrc=retDataObj.getBigDecimal("inTransitResrc");
							//首开在途(亿元)
							BigDecimal firstOpen=retDataObj.getBigDecimal("firstOpen");
							//续销在途(亿元)
							BigDecimal continueSale=retDataObj.getBigDecimal("continueSale");
							
							//是否满足预警条件
							String agStatus=Constants.NONE;
							vo.setFirstOpenOvhdRate("");
							if(firstOpenOvhdRate!=null) {
								agStatus=getStatus(cList, firstOpenOvhdRate);
								vo.setFirstOpenOvhdRate(firstOpenOvhdRate.toString());
							}
							String bgStatus=Constants.NONE;
							vo.setRenewalInTransitRate("");
							if(renewalInTransitRate!=null) {
								bgStatus=getStatus(dList, renewalInTransitRate);
								vo.setRenewalInTransitRate(renewalInTransitRate.toString());
							}
							vo.setInTransitResrc(inTransitResrc.toString());
							vo.setFirstOpen(firstOpen.toString());
							vo.setContinueSale(continueSale.toString());
							//(warning-预警标准-红色,remind-提醒标准-黄色,health-健康标准-绿色,none-没有)
							vo.setFirstOpenOvhdRate_status(agStatus);
							vo.setRenewalInTransitRate_status(bgStatus);
						}
					}
					
					return vo;
				}else {
					saveLog("获取产-汇总接口失败",logUrl,title,Constants.MONITORING_CONSOLE);
				}
			}
		}else {
			log.info("获取产-汇总接口失败");
			saveLog("获取产-汇总接口失败",logUrl,title,Constants.MONITORING_CONSOLE);
		}
		return vo;
	}
	
	
	
	/**
	 * 调用数据中台产-明细接口
	 * @param orgId 组织机构id
	 * @param reportDate 查询截止日期
	 */
	public ProduceItemVo getDataProduceItem(String orgId, String reportDate,List<MonitorConfigDetailDto> monitorConfigDetailDtoList,String hrOrgTypeId) {
		//切换下级类型
		hrOrgTypeId=getOrgNextType(hrOrgTypeId);
		ProduceItemVo vo=new ProduceItemVo();
		//产汇总
		ProduceVo produceVo=new ProduceVo();
		//日志路径
		String logUrl="MonitoringConsoleServiceImpl/getDataProduceItem";
		//标题
		String title="获取产-明细接口";
		
		BasicAuthClient bac = new BasicAuthClient();
		String api =produceItem_url+orgId+","+reportDate;
		//拼接地址
		String url = data_middle_ground_url+api;
		String result = bac.getData(url, data_api_key, data_api_value);
		log.info("###产-明细接口 地址： "+url);
		log.info("###产-明细接口 返回数据："+result);
		if(StrUtils.isNotEmpty(result)) {
			JSONObject jsonObject=JSONObject.parseObject(result);
			if(jsonObject!=null) {
				int retCode=jsonObject.getInteger("retCode");
				if(retCode==Constants.ZERO) {
					//首开项目开销比
					List<OrgRoundVo>firstOpenOvhdRateList=new ArrayList<>();
					//续销项目在途比
					List<OrgRoundVo>renewalInTransitRateList=new ArrayList<>();
					//在途资源(亿元)
					List<OrgRoundVo>inTransitResrcList=new ArrayList<>();
					//首开在途(亿元)
					List<OrgRoundVo>firstOpenList=new ArrayList<>();
					//续销在途(亿元)
					List<OrgRoundVo>continueSaleList=new ArrayList<>();
					//首开项目开销比配置详情
					List<MonitorConfigDetailDto>cList=monitorConfigDetailDtoList.stream()
							.filter(x->x.getTargetCode().equals(TargetNameEnum.C.getKey())).collect(Collectors.toList());
					//续销项目在途比配置详情
					List<MonitorConfigDetailDto>dList=monitorConfigDetailDtoList.stream()
							.filter(x->x.getTargetCode().equals(TargetNameEnum.D.getKey())).collect(Collectors.toList());
					
					//汇总组织机构信息和圆点
					List<OrgRoundVo>summaryOrgList=new ArrayList<>();
					//获取成功
					JSONArray retData=jsonObject.getJSONArray("retData");	
					if(retData != null) {
						for (int i = 0; i < retData.size(); i++) {
							JSONObject retDataObj=retData.getJSONObject(i);
							//首开项目开销比
							Double firstOpenOvhdRate=retDataObj.getDouble("firstOpenOvhdRate");
							//续销项目在途比
							Double renewalInTransitRate=retDataObj.getDouble("renewalInTransitRate");
							//在途资源(亿元)
							Double inTransitResrc=retDataObj.getDouble("inTransitResrc");
							//首开在途(亿元)
							Double firstOpen=retDataObj.getDouble("firstOpen");
							//续销在途(亿元)
							Double continueSale=retDataObj.getDouble("continueSale");
							//组织机构id
							String orgId1=retDataObj.getString("orgId");
							//组织机构名称
							String orgName=retDataObj.getString("orgName");
							
							//首开项目开销比
							OrgRoundVo firstOpenOvhdRateVo=getOrgRoundStatus(orgName, cList, orgId1, firstOpenOvhdRate, hrOrgTypeId);
							//续销项目在途比
							OrgRoundVo renewalInTransitRateVo=getOrgRoundStatus(orgName, dList, orgId1, renewalInTransitRate, hrOrgTypeId);
							//在途资源(亿元)
							OrgRoundVo inTransitResrcVo=getOrgRoundNoStatus(orgName, orgId1, inTransitResrc, hrOrgTypeId);
							//首开在途(亿元)
							OrgRoundVo firstOpenVo=getOrgRoundNoStatus(orgName, orgId1, firstOpen, hrOrgTypeId);
							//续销在途(亿元)
							OrgRoundVo continueSaleVo=getOrgRoundNoStatus(orgName, orgId1, continueSale, hrOrgTypeId);
							
							if(firstOpenOvhdRateVo.getResourceStatus().equals(Constants.WARNING) && renewalInTransitRateVo.getResourceStatus().equals(Constants.WARNING)) {
								//2个条件都存在把组织机构放进去
								OrgRoundVo orgVo=getOrgRoundWarning(orgName, orgId1, hrOrgTypeId);
								summaryOrgList.add(orgVo);
							}
							//最后把vo放到list里面
							firstOpenOvhdRateList.add(firstOpenOvhdRateVo);
							renewalInTransitRateList.add(renewalInTransitRateVo);
							inTransitResrcList.add(inTransitResrcVo);
							firstOpenList.add(firstOpenVo);
							continueSaleList.add(continueSaleVo);
						}
					}
					
					//预警红黄绿
					StrUtils.compareOrder(firstOpenOvhdRateList);
					StrUtils.compareOrder(renewalInTransitRateList);
					
					//亿元 从大到小
					inTransitResrcList.sort((OrgRoundVo o1, OrgRoundVo o2)->o2.getQuotaVal().compareTo(o1.getQuotaVal()));
					firstOpenList.sort((OrgRoundVo o1, OrgRoundVo o2)->o2.getQuotaVal().compareTo(o1.getQuotaVal()));
					continueSaleList.sort((OrgRoundVo o1, OrgRoundVo o2)->o2.getQuotaVal().compareTo(o1.getQuotaVal()));
					//把都符合条件的组织机构信息都放进去
					produceVo.setOrgRoundList(summaryOrgList);
					
					//把list放到大的vo里面
					vo.setFirstOpenOvhdRateList(firstOpenOvhdRateList);
					vo.setRenewalInTransitRateList(renewalInTransitRateList);
					vo.setInTransitResrcList(inTransitResrcList);
					vo.setFirstOpenList(firstOpenList);
					vo.setContinueSaleList(continueSaleList);
					vo.setProduceVo(produceVo);
				}else {
					saveLog("获取产-明细接口失败",logUrl,title,Constants.MONITORING_CONSOLE);
				}
			}
		}else {
			log.info("获取产-明细接口失败");
			saveLog("获取产-明细接口失败",logUrl,title,Constants.MONITORING_CONSOLE);
		}
		return vo;
	}

	/**
	 * 封装一个有状态的组织和圆点vo
	 * @param orgName
	 * @param list
	 * @param orgId1
	 * @param value
	 * @param hrOrgTypeId
	 * @return
	 */
	public OrgRoundVo getOrgRoundStatus(String orgName,List<MonitorConfigDetailDto>list,String orgId1
			,Double value,String hrOrgTypeId) {
		OrgRoundVo vo=new OrgRoundVo();
		vo.setOrgName(orgName);
		//圆点状态(warning-预警标准-红色,remind-提醒标准-黄色,health-健康标准-绿色)
		String status=getStatus(list, value == null ? 0 : value.doubleValue());
		vo.setResourceStatus(status);
		vo.setQuotaVal(value == null ? BigDecimal.ZERO : BigDecimal.valueOf(value.doubleValue()).setScale(2, RoundingMode.HALF_UP));
		vo.setOrgId(orgId1);
		vo.setOrgType(hrOrgTypeId);
		vo.setGroup(StrUtils.getStatusGroup(status));
		return vo;
	}


	/**
	 * 封装一个没有状态的组织和圆点vo
	 * @param orgName
	 * @param orgId1
	 * @param value
	 * @param hrOrgTypeId
	 * @return
	 */
	public OrgRoundVo getOrgRoundNoStatus(String orgName,String orgId1
			,Double value,String hrOrgTypeId) {
		OrgRoundVo vo=new OrgRoundVo();
		vo.setOrgName(orgName);
		//圆点状态(warning-预警标准-红色,remind-提醒标准-黄色,health-健康标准-绿色)
		vo.setResourceStatus(Constants.NONE);
		vo.setQuotaVal(value == null ? BigDecimal.ZERO : BigDecimal.valueOf(value.doubleValue()));
		vo.setOrgId(orgId1);
		vo.setOrgType(hrOrgTypeId);
		vo.setGroup(Constants.ZERO);
		return vo;
	}

	/**
	 * 封装一个没有状态的组织和圆点vo
	 * @param orgName
	 * @param orgId1
	 * @param value
	 * @param hrOrgTypeId
	 * @return
	 */
	public OrgRoundVo getOrgRoundNoStatus(String orgName,String orgId1
			,BigDecimal value,String hrOrgTypeId) {
		OrgRoundVo vo=new OrgRoundVo();
		vo.setOrgName(orgName);
		//圆点状态(warning-预警标准-红色,remind-提醒标准-黄色,health-健康标准-绿色)
		vo.setResourceStatus(Constants.NONE);
		vo.setQuotaVal(value == null ? BigDecimal.ZERO : value);
		vo.setOrgId(orgId1);
		vo.setOrgType(hrOrgTypeId);
		vo.setGroup(Constants.ZERO);
		return vo;
	}

	/**
	 *  封装一个没有状态的组织和圆点vo
	 * @param orgName
	 * @param orgId1
	 * @param firstHalfYearSupplyRate
	 * @param secondHalfYearSupplyRate
	 * @param halfYearSupplyRate
	 * @param hrOrgTypeId
	 * @return
	 */
	public OrgRoundToStrQuotaValVo getOrgRoundNoStatus(String orgName,String orgId1
			,BigDecimal firstHalfYearSupplyRate,BigDecimal secondHalfYearSupplyRate,Double halfYearSupplyRate,String hrOrgTypeId) {
		OrgRoundToStrQuotaValVo vo=new OrgRoundToStrQuotaValVo();
		vo.setOrgName(orgName);
		//圆点状态(warning-预警标准-红色,remind-提醒标准-黄色,health-健康标准-绿色)
		vo.setResourceStatus(Constants.NONE);
		vo.setQuotaVal(firstHalfYearSupplyRate+":"+secondHalfYearSupplyRate);
		vo.setOrgId(orgId1);
		vo.setOrgType(hrOrgTypeId);
		vo.setGroup(Constants.ZERO);
		vo.setFirstHalfYearSupplyRate(firstHalfYearSupplyRate == null ? BigDecimal.ZERO : firstHalfYearSupplyRate);
		vo.setSecondHalfYearSupplyRate(secondHalfYearSupplyRate == null ? BigDecimal.ZERO : secondHalfYearSupplyRate);
		vo.setHalfYearSupplyRate(halfYearSupplyRate == null ? BigDecimal.ZERO : BigDecimal.valueOf(halfYearSupplyRate.doubleValue()));
		return vo;
	}
	
	/**
	 * 封装一个都是预警标准的vo
	 * @param orgName
	 * @param orgId1
	 * @param hrOrgTypeId
	 * @return
	 */
	public OrgRoundVo getOrgRoundWarning(String orgName,String orgId1,String hrOrgTypeId) {
		OrgRoundVo orgVo=new OrgRoundVo();
		orgVo.setOrgName(orgName);
		//圆点状态(warning-预警标准-红色,remind-提醒标准-黄色,health-健康标准-绿色)
		orgVo.setResourceStatus(Constants.WARNING);
		orgVo.setQuotaVal(new BigDecimal(0));
		orgVo.setOrgId(orgId1);
		orgVo.setOrgType(hrOrgTypeId);
		orgVo.setGroup(Constants.ONE);
		return orgVo;
	}
	
	
	/**
	 * 调用数据中台供-汇总接口
	 * @param orgId 组织机构id
	 * @param reportDate 查询截止日期
	 */
	public SupplyVo getDataSupply(String orgId, String reportDate,List<MonitorConfigDetailDto>monitorConfigDetailDtoList) {
		SupplyVo vo=new SupplyVo();
		//日志路径
		String logUrl="MonitoringConsoleServiceImpl/getDataSupply";
		//标题
		String title="获取供-汇总接口";
		BasicAuthClient bac = new BasicAuthClient();
		String api =supply_url+orgId+","+reportDate;
		//拼接地址
		String url = data_middle_ground_url+api;
		String result = bac.getData(url, data_api_key, data_api_value);
		log.info("###供-汇总接口 地址： "+url);
		log.info("###供-汇总接口 返回数据："+result);
		if(StrUtils.isNotEmpty(result)) {
			JSONObject jsonObject=JSONObject.parseObject(result);
			if(jsonObject!=null) {
				int retCode=jsonObject.getInteger("retCode");
				if(retCode==Constants.ZERO) {
					JSONArray retData=jsonObject.getJSONArray("retData");	
					if(retData != null) {
						for (int i = 0; i < retData.size(); i++) {
							JSONObject retDataObj=retData.getJSONObject(i);
							//年度供应达成率(百分比)
							Double yearSupplyReachRate=retDataObj.getDouble("yearSupplyReachRate");
							//季度供应达成率(百分比)
							Double seasonSupplyReachRate=retDataObj.getDouble("seasonSupplyReachRate");
							//月度供应达成率(百分比)
							Double monthSupplyReachRate=retDataObj.getDouble("monthSupplyReachRate");
							//年度累计供货
							BigDecimal yearSupply=retDataObj.getBigDecimal("yearSupply");
							//季度累计供货
							BigDecimal seasonSupply=retDataObj.getBigDecimal("seasonSupply");
							//月度实际供货
							BigDecimal monthSupply=retDataObj.getBigDecimal("monthSupply");
							//上下半年供应比-上半年数值
							BigDecimal firstHalfYearSupplyRate=retDataObj.getBigDecimal("firstHalfYearSupplyRate");
							//上下半年供应比-下半年数值
							BigDecimal secondHalfYearSupplyRate=retDataObj.getBigDecimal("secondHalfYearSupplyRate");
		
							//是否满足预警条件
							String agStatus=Constants.NONE;
							vo.setHalfYearSupplyRate("");
							vo.setYearSupplyReachRate(yearSupplyReachRate.toString());
							vo.setSeasonSupplyReachRate(seasonSupplyReachRate.toString());
							vo.setMonthSupplyReachRate(monthSupplyReachRate.toString());
							//(warning-预警标准-红色,remind-提醒标准-黄色,health-健康标准-绿色,none-没有)
							vo.setHalfYearSupplyRate_status(agStatus);
		
							vo.setYearSupply(yearSupply==null?null:yearSupply.toString());
							vo.setSeasonSupply(seasonSupply==null?null:seasonSupply.toString());
							vo.setMonthSupply(monthSupply==null?null:monthSupply.toString());
							vo.setFirstHalfYearSupplyRate(firstHalfYearSupplyRate==null?null:firstHalfYearSupplyRate.toString());
							vo.setSecondHalfYearSupplyRate(secondHalfYearSupplyRate==null?null:secondHalfYearSupplyRate.toString());
						}
					}
					return vo;
				}else {
					saveLog("获取供-汇总接口失败",logUrl,title,Constants.MONITORING_CONSOLE);
				}
			}
		}else {
			log.info("获取供-汇总接口失败");
			saveLog("获取供-汇总接口失败",logUrl,title,Constants.MONITORING_CONSOLE);
		}
		return vo;
	}
	
	
	/**
	 * 调用数据中台供-明细接口
	 * @param orgId 组织机构id
	 * @param reportDate 查询截止日期
	 */
	public SupplyItemVo getDataSupplyItem(String orgId, String reportDate,List<MonitorConfigDetailDto> monitorConfigDetailDtoList,String hrOrgTypeId) {
		//切换下级类型
		hrOrgTypeId=getOrgNextType(hrOrgTypeId);
		SupplyItemVo vo=new SupplyItemVo();
		//日志路径
		String logUrl="MonitoringConsoleServiceImpl/getDataSupplyItem";
		//标题
		String title="获取供-明细接口";
		BasicAuthClient bac = new BasicAuthClient();
		String api =supplyItem_url+orgId+","+reportDate;
		//拼接地址
		String url = data_middle_ground_url+api;
		String result = bac.getData(url, data_api_key, data_api_value);
		JSONObject jsonObject=JSONObject.parseObject(result);
		if(jsonObject!=null) {
			int retCode=jsonObject.getInteger("retCode");
			//0
			if(retCode==Constants.ZERO) {
				//上下半年供应比(百分比)
				List<OrgRoundToStrQuotaValVo>halfYearSupplyRateList=new LinkedList<>();
				//年度供应达成率(百分比)
				List<OrgRoundVo>yearSupplyReachRateList=new ArrayList<>();
				//季度供应达成率(百分比)
				List<OrgRoundVo>seasonSupplyReachRateList=new ArrayList<>();
				//月度供应达成率(百分比)
				List<OrgRoundVo>monthSupplyReachRateList=new ArrayList<>();
				//月度供应达成率(百分比)
				List<OrgRoundVo>yearSupplyList=new ArrayList<>();
				//月度供应达成率(百分比)
				List<OrgRoundVo>seasonSupplyList=new ArrayList<>();
				//月度供应达成率(百分比)
				List<OrgRoundVo>monthSupplyList=new ArrayList<>();

				//获取成功
				JSONArray retData=jsonObject.getJSONArray("retData");	
				for (int i = 0; i < retData.size(); i++) {
					JSONObject retDataObj=retData.getJSONObject(i);
					//上下半年供应比(百分比)
					Double halfYearSupplyRate=retDataObj.getDouble("halfYearSupplyRate");
					//年度供应达成率(百分比)
					Double yearSupplyReachRate=retDataObj.getDouble("yearSupplyReachRate");
					//季度供应达成率(百分比)
					Double seasonSupplyReachRate=retDataObj.getDouble("seasonSupplyReachRate");
					//月度供应达成率(百分比)
					Double monthSupplyReachRate=retDataObj.getDouble("monthSupplyReachRate");
					//组织机构id
					String orgId1=retDataObj.getString("orgId");
					//组织机构名称
					String orgName=retDataObj.getString("orgName");
					//年度累计供货
					BigDecimal yearSupply=retDataObj.getBigDecimal("yearSupply");
					//季度累计供货
					BigDecimal seasonSupply=retDataObj.getBigDecimal("seasonSupply");
					//月度实际供货
					BigDecimal monthSupply=retDataObj.getBigDecimal("monthSupply");
					//上下半年供应比-上半年数值
					BigDecimal firstHalfYearSupplyRate=retDataObj.getBigDecimal("firstHalfYearSupplyRate");
					//上下半年供应比-下半年数值
					BigDecimal secondHalfYearSupplyRate=retDataObj.getBigDecimal("secondHalfYearSupplyRate");

					//上下半年供应比(百分比)
					OrgRoundToStrQuotaValVo halfYearSupplyRateVo=getOrgRoundNoStatus(orgName, orgId1, firstHalfYearSupplyRate, secondHalfYearSupplyRate, halfYearSupplyRate, hrOrgTypeId);
					//年度供应达成率(百分比)
					OrgRoundVo yearSupplyReachRateVo=getOrgRoundNoStatus(orgName, orgId1, yearSupplyReachRate, hrOrgTypeId);
					//季度供应达成率(百分比)
					OrgRoundVo seasonSupplyReachRateVo=getOrgRoundNoStatus(orgName, orgId1, seasonSupplyReachRate, hrOrgTypeId);
					//月度供应达成率(百分比)
					OrgRoundVo monthSupplyReachRateVo=getOrgRoundNoStatus(orgName, orgId1, monthSupplyReachRate, hrOrgTypeId);

					//年度累计供货
					OrgRoundVo yearSupplyVo=getOrgRoundNoStatus(orgName, orgId1, yearSupply, hrOrgTypeId);
					//年度累计供货
					OrgRoundVo seasonSupplyVo=getOrgRoundNoStatus(orgName, orgId1, seasonSupply, hrOrgTypeId);
					//年度累计供货
					OrgRoundVo monthSupplyVo=getOrgRoundNoStatus(orgName, orgId1, monthSupply, hrOrgTypeId);

					//最后把vo放到list里面
					halfYearSupplyRateList.add(halfYearSupplyRateVo);
					yearSupplyReachRateList.add(yearSupplyReachRateVo);
					seasonSupplyReachRateList.add(seasonSupplyReachRateVo);
					monthSupplyReachRateList.add(monthSupplyReachRateVo);
					yearSupplyList.add(yearSupplyVo);
					seasonSupplyList.add(seasonSupplyVo);
					monthSupplyList.add(monthSupplyVo);
				}
				
				seasonSupplyReachRateList.sort((OrgRoundVo o1, OrgRoundVo o2)->o2.getQuotaVal().compareTo(o1.getQuotaVal()));
				monthSupplyReachRateList.sort((OrgRoundVo o1, OrgRoundVo o2)->o2.getQuotaVal().compareTo(o1.getQuotaVal()));
				yearSupplyList.sort((OrgRoundVo o1, OrgRoundVo o2)->o2.getQuotaVal().compareTo(o1.getQuotaVal()));
				seasonSupplyList.sort((OrgRoundVo o1, OrgRoundVo o2)->o2.getQuotaVal().compareTo(o1.getQuotaVal()));
				monthSupplyList.sort((OrgRoundVo o1, OrgRoundVo o2)->o2.getQuotaVal().compareTo(o1.getQuotaVal()));

				//把list放到大的vo里面
				vo.setHalfYearSupplyRateList(halfYearSupplyRateList);
				vo.setYearSupplyReachRateList(yearSupplyReachRateList);
				vo.setSeasonSupplyReachRateList(seasonSupplyReachRateList);
				vo.setMonthSupplyReachRateList(monthSupplyReachRateList);
				vo.setYearSupplyList(yearSupplyList);
				vo.setSeasonSupplyList(seasonSupplyList);
				vo.setMonthSupplyList(monthSupplyList);
			}else {
				saveLog("获取供-明细接口失败",logUrl,title,Constants.MONITORING_CONSOLE);
			}
		}else {
			log.info("获取供-明细接口失败");
			saveLog("获取供-明细接口失败",logUrl,title,Constants.MONITORING_CONSOLE);
		}
		return vo;
	}

	
	
	/**
	 * 调用数据中台销-汇总接口
	 * @param orgId 组织机构id
	 * @param reportDate 查询截止日期
	 */
	public SaleVo getDataSale(String orgId, String reportDate,List<MonitorConfigDetailDto> monitorConfigDetailDtoList) {
		//首开去化率配置详情
		List<MonitorConfigDetailDto>fList=monitorConfigDetailDtoList.stream()
				.filter(x->x.getTargetCode().equals(TargetNameEnum.F.getKey())).collect(Collectors.toList());
		//月度去化率配置详情
		List<MonitorConfigDetailDto>gList=monitorConfigDetailDtoList.stream()
				.filter(x->x.getTargetCode().equals(TargetNameEnum.G.getKey())).collect(Collectors.toList());
		//新供去化率
		List<MonitorConfigDetailDto>hList=monitorConfigDetailDtoList.stream()
				.filter(x->x.getTargetCode().equals(TargetNameEnum.H.getKey())).collect(Collectors.toList());
		//库存去化率
		List<MonitorConfigDetailDto>iList=monitorConfigDetailDtoList.stream()
				.filter(x->x.getTargetCode().equals(TargetNameEnum.I.getKey())).collect(Collectors.toList());
		//长期库存去化率	
		List<MonitorConfigDetailDto>jList=monitorConfigDetailDtoList.stream()
				.filter(x->x.getTargetCode().equals(TargetNameEnum.J.getKey())).collect(Collectors.toList());
		//现房库存去化率
		List<MonitorConfigDetailDto>kList=monitorConfigDetailDtoList.stream()
				.filter(x->x.getTargetCode().equals(TargetNameEnum.K.getKey())).collect(Collectors.toList());
		
		SaleVo vo=new SaleVo();
		//日志路径
		String logUrl="MonitoringConsoleServiceImpl/getDataSale";
		//标题
		String title="获取销-汇总接口";
		
		BasicAuthClient bac = new BasicAuthClient();
		String api =sale_url+orgId+","+reportDate;
		//拼接地址
		String url = data_middle_ground_url+api;
		String result = bac.getData(url, data_api_key, data_api_value);
		log.info("###销-汇总接口 地址： "+url);
		log.info("###销-汇总接口 返回数据："+result);
		if(StrUtils.isNotEmpty(result)) {
			JSONObject jsonObject=JSONObject.parseObject(result);
			if(jsonObject!=null) {
				int retCode=jsonObject.getInteger("retCode");
				if(retCode==Constants.ZERO) {
					JSONArray retData=jsonObject.getJSONArray("retData");	
					if(retData != null) {
						for (int i = 0; i < retData.size(); i++) {
							JSONObject retDataObj=retData.getJSONObject(i);
							//首开去化率
							Double firstOpenRate=retDataObj.getDouble("firstOpenRate");
							//月度去化率
							Double monthRate=retDataObj.getDouble("MonthRate");
							//新供去化率
							Double newSupplyRemovalRate=retDataObj.getDouble("newSupplyRemovalRate");
							//库存去化率
							Double stockRemovalRate=retDataObj.getDouble("stockRemovalRate");
							//长期库存去化率	
							Double stockRemovalRatelongtime=retDataObj.getDouble("stockRemovalRatelongtime");
							//现房库存去化率
							Double saleRateExit=retDataObj.getDouble("saleRateExit");
							//年度考核指标完成率
							Double checkRateYear=retDataObj.getDouble("checkRateYear");
							//累计月度完成率
							Double checkRateMonth=retDataObj.getDouble("checkRateMonth");
							//当月滚动版完成率
							Double checkRateThisMonth=retDataObj.getDouble("checkRateThisMonth");
							//月度实际销售
							BigDecimal monthActualSale=retDataObj.getBigDecimal("monthActualSale");
							//月度销售达成率
							BigDecimal monthSaleRate=retDataObj.getBigDecimal("monthSaleRate");
		
							// 是否满足预警条件
							String fStatus = Constants.NONE;
							String gStatus = Constants.NONE;
							String hStatus = Constants.NONE;
							String iStatus = Constants.NONE;
							String jStatus = Constants.NONE;
							String kStatus = Constants.NONE;
							String mStatus = Constants.NONE;
							String nStatus = Constants.NONE;
							
							vo.setFirstOpenRate("");
							if(firstOpenRate!=null) {
								fStatus = getStatus(fList, firstOpenRate);
								vo.setFirstOpenRate(firstOpenRate.toString());
							}
							vo.setMonthRate("");
							if(monthRate!=null) {
								gStatus = getStatus(gList, monthRate);
								vo.setMonthRate(monthRate.toString());
							}
							vo.setNewSupplyRemovalRate("");
							if(newSupplyRemovalRate!=null) {
								hStatus = getStatus(hList, newSupplyRemovalRate);
								vo.setNewSupplyRemovalRate(newSupplyRemovalRate.toString());
							}
							vo.setStockRemovalRate("");
							if(stockRemovalRate!=null) {
								iStatus = getStatus(iList, stockRemovalRate);
								vo.setStockRemovalRate(stockRemovalRate.toString());
							}
							vo.setStockRemovalRatelongtime("");
							if(stockRemovalRatelongtime!=null) {
								jStatus = getStatus(jList, stockRemovalRatelongtime);
								vo.setStockRemovalRatelongtime(stockRemovalRatelongtime.toString());
							}
							vo.setSaleRateExit("");
							if(saleRateExit!=null) {
								kStatus = getStatus(kList,saleRateExit);
								vo.setSaleRateExit(saleRateExit.toString());
							}
							
							vo.setCheckRateYear("");
							if(checkRateYear!=null) {
								vo.setCheckRateYear(checkRateYear.toString());
							}
							
							if(checkRateMonth!=null) {
								vo.setCheckRateMonth(checkRateMonth.toString());
							}
		
							if(checkRateThisMonth!=null) {
								vo.setCheckRateThisMonth(checkRateThisMonth.toString());
							}
		
							if(monthActualSale!=null) {
								vo.setMonthActualSale(monthActualSale.toString());
							}
		
							if(monthSaleRate!=null) {
								vo.setMonthSaleRate(monthSaleRate.toString());
							}
		
							//状态(warning-预警标准-红色,remind-提醒标准-黄色,health-健康标准-绿色,none-没有)
							vo.setFirstOpenRate_status(fStatus);
							vo.setMonthRate_status(gStatus);
							vo.setNewSupplyRemovalRate_status(hStatus);
							vo.setStockRemovalRate_status(iStatus);
							vo.setStockRemovalRatelongtime_status(jStatus);
							vo.setSaleRateExit_status(kStatus);
							vo.setMonthActualSale_status(mStatus);
							vo.setMonthSaleRate_status(nStatus);
						}
					}
					return vo;
				}else {
					saveLog("获取销-汇总接口失败",logUrl,title,Constants.MONITORING_CONSOLE);
				}
			}
		}else {
			log.info("获取销-汇总接口失败");
			saveLog("获取销-汇总接口失败",logUrl,title,Constants.MONITORING_CONSOLE);
		}
		return vo;
	}
	
	
	/**
	 * 调用数据中台存-汇总接口
	 * @param orgId 组织机构id
	 * @param reportDate 查询截止日期
	 */
	public StockVo getDataStock(String orgId, String reportDate,List<MonitorConfigDetailDto> monitorConfigDetailDtoList) {
		StockVo vo=new StockVo();
		//日志路径
		String logUrl="MonitoringConsoleServiceImpl/getDataStock";
		//标题
		String title="获取存-汇总接口";
		//存销比配置详情
		List<MonitorConfigDetailDto>lList=monitorConfigDetailDtoList.stream()
				.filter(x->x.getTargetCode().equals(TargetNameEnum.L.getKey())).collect(Collectors.toList());
		//长期库存占比(百分比) 配置详情
		List<MonitorConfigDetailDto>mList=monitorConfigDetailDtoList.stream()
				.filter(x->x.getTargetCode().equals(TargetNameEnum.M.getKey())).collect(Collectors.toList());
		//长期库存存销比配置详情
		List<MonitorConfigDetailDto>oList=monitorConfigDetailDtoList.stream()
				.filter(x->x.getTargetCode().equals(TargetNameEnum.O.getKey())).collect(Collectors.toList());
		//现房库存存销比配置详情
		List<MonitorConfigDetailDto>pList=monitorConfigDetailDtoList.stream()
				.filter(x->x.getTargetCode().equals(TargetNameEnum.P.getKey())).collect(Collectors.toList());
		
		BasicAuthClient bac = new BasicAuthClient();
		String api =stock_url+orgId+","+reportDate;
		//拼接地址
		String url = data_middle_ground_url+api;
		String result =  bac.getData(url, data_api_key, data_api_value);
		log.info("###存-汇总接口 地址： "+url);
		log.info("###存-汇总接口 返回数据："+result);
		if(StrUtils.isNotEmpty(result)) {
			JSONObject jsonObject=JSONObject.parseObject(result);
			if(jsonObject!=null) {
				int retCode=jsonObject.getInteger("retCode");
				//0
				if(retCode==Constants.ZERO) {
					//获取成功
					JSONArray retData=jsonObject.getJSONArray("retData");
					if (retData != null){
						for (int i = 0; i < retData.size(); i++) {
							JSONObject retDataObj=retData.getJSONObject(i);
							//库存(亿元)
							BigDecimal store=retDataObj.getBigDecimal("store");
							//已达未取(亿元)
							BigDecimal hasNotToken=retDataObj.getBigDecimal("hasNotToken");
							//真实库存(亿元)
							BigDecimal realStore=retDataObj.getBigDecimal("realStore");
							//存销比
							Double storeSaleRate=retDataObj.getDouble("storeSaleRate");
							//长期库存占比(百分比)
							Double storeRatelongTime=retDataObj.getDouble("storeRatelongTime");
							//新增长期库存(亿元)
							BigDecimal storeAdd=retDataObj.getBigDecimal("storeAdd");
							//长期库存
							BigDecimal storeLongTime=retDataObj.getBigDecimal("storeLongTime");
							//长期库存存销比
							Double storeSaleRatelongtime=retDataObj.getDouble("storeSaleRatelongtime");
							//现房库存
							BigDecimal storeExist=retDataObj.getBigDecimal("storeExist");
							//现房库存存销比
							Double storeSaleRateexit=retDataObj.getDouble("storeSaleRateexit");
							//现房库存占比(百分比)
							Double storeExistRate=retDataObj.getDouble("storeExistRate");
							//新增现房库存(亿元)
							BigDecimal storeExistAdd=retDataObj.getBigDecimal("storeExistAdd");
							//返回状态
							String storeSaleRate_status=Constants.NONE;
							String storeSaleRatelongtime_status=Constants.NONE;
							String storeRatelongTime_status=Constants.NONE;
							String storeSaleRateexit_status=Constants.NONE;

							vo.setStoreSaleRate("");
							if(storeSaleRate!=null) {
								storeSaleRate_status=getStatus(lList, storeSaleRate);
								vo.setStoreSaleRate(storeSaleRate.toString());
							}

							vo.setStoreSaleRatelongtime("");
							if(storeSaleRatelongtime!=null) {
								storeSaleRatelongtime_status=getStatus(oList, storeSaleRatelongtime);
								vo.setStoreSaleRatelongtime(storeSaleRatelongtime.toString());
							}
							vo.setStoreRatelongTime("");
							if(storeRatelongTime!=null) {
								storeRatelongTime_status=getStatus(mList, storeRatelongTime);
								vo.setStoreRatelongTime(storeRatelongTime.toString());
							}
							vo.setStoreSaleRateexit("");
							if(storeSaleRateexit!=null) {
								storeSaleRateexit_status=getStatus(pList, storeSaleRateexit);
								vo.setStoreSaleRateexit(storeSaleRateexit.toString());
							}

							vo.setStore(store.toString());
							vo.setHasNotToken(hasNotToken.toString());
							vo.setRealStore(realStore.toString());


							vo.setStoreAdd(storeAdd.toString());

							vo.setStoreLongTime("");
							if(storeLongTime!=null) {
								vo.setStoreLongTime(storeLongTime.toString());
							}

							vo.setStoreExist("");
							if(storeExist!=null) {
								vo.setStoreExist(storeExist.toString());
							}

							vo.setStoreExistRate("");
							if(storeExistRate!=null) {
								vo.setStoreExistRate(storeExistRate.toString());
							}

							vo.setStoreExistAdd(storeExistAdd.toString());

							//状态(warning-预警标准-红色,remind-提醒标准-黄色,health-健康标准-绿色,none-没有)
							vo.setStoreSaleRate_status(storeSaleRate_status);
							vo.setStoreSaleRatelongtime_status(storeSaleRatelongtime_status);
							vo.setStoreRatelongTime_status(storeRatelongTime_status);
							vo.setStoreSaleRateexit_status(storeSaleRateexit_status);
						}
					}

					return vo;
				}else {
					//获取失败
					saveLog("获取存-汇总接口失败",logUrl,title,Constants.MONITORING_CONSOLE);
				}
			}
		}else {
			log.info("获取存-汇总接口失败");
			saveLog("获取存-汇总接口失败",logUrl,title,Constants.MONITORING_CONSOLE);
		}
		return vo;
	}

	
	
	/**
	 * 调用数据中台结-汇总接口
	 * @param orgId 组织机构id
	 * @param reportDate 查询截止日期
	 */
	public StatementVo getDataStatement(String orgId, String reportDate,List<MonitorConfigDetailDto> monitorConfigDetailDtoList) {
		StatementVo vo=new StatementVo();
		//日志路径
		String logUrl="MonitoringConsoleServiceImpl/getDataStatement";
		//标题
		String title="获取结-汇总接口";
		//截取月份
		String month=reportDate.substring(4,6);
		//结转去化率(上半年)配置详情
		List<MonitorConfigDetailDto>qList=new ArrayList<>();

		// 结转去化率 1-6月取上半年
		if(Integer.parseInt(month) <= Constants.SIX) {
			qList = monitorConfigDetailDtoList.stream()
					.filter(x -> x.getTargetCode().equals(TargetNameEnum.Q.getKey()))
					.collect(Collectors.toList());
		}
		// 结转去化率 7-12取下半年
		if(Integer.parseInt(month) >= Constants.SEVEN) {
			qList = monitorConfigDetailDtoList.stream()
					.filter(x -> x.getTargetCode().equals(TargetNameEnum.R.getKey()))
					.collect(Collectors.toList());
		}
		
		BasicAuthClient bac = new BasicAuthClient();
		String api =statement_url+orgId+","+reportDate;
		//拼接地址
		String url = data_middle_ground_url+api;
		String result =  bac.getData(url, data_api_key, data_api_value);
		JSONObject jsonObject=JSONObject.parseObject(result);
		if(jsonObject!=null) {
			int retCode=jsonObject.getInteger("retCode");
			//0
			if(retCode==Constants.ZERO) {
				//获取成功
				JSONArray retData=jsonObject.getJSONArray("retData");
				if (retData != null) {
					for (int i = 0; i < retData.size(); i++) {
						JSONObject retDataObj = retData.getJSONObject(i);
						//结转去化率(百分比)
						Double statementRate = retDataObj.getDouble("statementRate");
						//业绩锁定率(百分比)
						Double achievementLockRate = retDataObj.getDouble("achievementLockRate");
						//可结转资源(亿元)
						BigDecimal statementValue = retDataObj.getBigDecimal("statementValue");
						//返回状态
						String statementRate_status = Constants.NONE;
						vo.setStatementRate("");
						if (statementRate != null) {
							statementRate_status = getStatus(qList, statementRate);
							vo.setStatementRate(statementRate.toString());
						}
						vo.setAchievementLockRate("");
						if (achievementLockRate != null) {
							vo.setAchievementLockRate(achievementLockRate.toString());
						}
						vo.setStatementValue("");
						if (statementValue != null) {
							vo.setStatementValue(statementValue.toString());
						}
						//结转去化率状态(warning-预警标准-红色,remind-提醒标准-黄色,health-健康标准-绿色,none-没有)
						vo.setStatementRate_status(statementRate_status);
					}
				}
				return vo;
			}else {
				//获取失败
				saveLog("获取结-汇总接口失败",logUrl,title,Constants.MONITORING_CONSOLE);
			}
		}else {
			log.info("获取结-汇总接口失败");
			saveLog("获取结-汇总接口失败",logUrl,title,Constants.MONITORING_CONSOLE);
		}
		return vo;
	}
	
	/**
     * 调用数据中台 回-汇总接口
     *
     * @return
     */
    private ReturnVo getDataReturn(String orgId, String reportDate, List<MonitorConfigDetailDto> monitorConfigDetailDtoList) {
        //监控台-回 配置详情
        List<MonitorConfigDetailDto> rList = monitorConfigDetailDtoList.stream()
                .filter(x -> x.getTargetCode().equals(TargetNameEnum.S.getKey())).collect(Collectors.toList());
        //获取监控台-回数据
        SupervisoryConsoleReturnDetail returnDetail = supervisoryConsoleReturnDetailMapper.getReturnDetailByOrgId(orgId, reportDate);

		//年度签约回款率
		Double returnYearSign = 0.0;
		//年度综合回款率
		Double returnAllYearSign = 0.0;
		//滚动综合回款率
		Double rollReturn = 0.0;
        if(null != returnDetail){
			returnYearSign = returnDetail.getReturnYearSign();
			returnAllYearSign = returnDetail.getReturnAllYearSign();
			rollReturn = returnDetail.getRollReturn();
		}

		ReturnVo vo = new ReturnVo();
		vo.setReturnYearSign(returnYearSign.toString());
		vo.setReturnAllYearSign(returnAllYearSign.toString());
		vo.setRollReturn(rollReturn.toString());
		//状态(warning-预警标准-红色,remind-提醒标准-黄色,health-健康标准-绿色,none-没有)
		vo.setReturnYearSign_status(getStatus(rList, returnYearSign));
		vo.setReturnAllYearSign_status(getStatus(rList, returnAllYearSign));
		vo.setRollReturn_status(getStatus(rList, rollReturn));
        return vo;
    }
	
	
	/**
	 * 调用数据中台-销明细接口
	 * @param orgId 组织机构id
	 * @param reportDate 查询截止日期
	 */
	public SaleItemVo getDataSaleItem(String orgId, String reportDate,List<MonitorConfigDetailDto> monitorConfigDetailDtoList,String hrOrgTypeId) {
		//切换下级类型
		hrOrgTypeId=getOrgNextType(hrOrgTypeId);
		SaleItemVo vo=new SaleItemVo();
		//销汇总
		SaleVo saleVo=new SaleVo();
		//日志路径
		String logUrl="MonitoringConsoleServiceImpl/getDataSaleItem";
		//标题
		String title="获取销-明细接口";
		
		BasicAuthClient bac = new BasicAuthClient();
		String api =saleItem_url+orgId+","+reportDate;
		//拼接地址
		String url = data_middle_ground_url+api;
		String result =  bac.getData(url, data_api_key, data_api_value);
		log.info("###销-明细接口 地址： "+url);
		log.info("###销-明细接口 返回数据："+result);
		if(StrUtils.isNotEmpty(result)) {
			JSONObject jsonObject=JSONObject.parseObject(result);
			if(jsonObject!=null) {
				int retCode=jsonObject.getInteger("retCode");
				if(retCode==Constants.ZERO) {
					//首开去化率
					List<OrgRoundVo>firstOpenRateList=new ArrayList<>();
					//月度去化率
					List<OrgRoundVo>monthRateList=new ArrayList<>();
					//新供去化率
					List<OrgRoundVo>newSupplyRemovalRateList=new ArrayList<>();
					//库存去化率
					List<OrgRoundVo>stockRemovalRateList=new ArrayList<>();
					//长期库存去化率	
					List<OrgRoundVo>stockRemovalRatelongTimeList=new ArrayList<>();
					//现房库存去化率
					List<OrgRoundVo>saleRateExitList=new ArrayList<>();
					//年度考核指标完成率
					List<OrgRoundVo>checkRateYearList=new ArrayList<>();
					//累计月度完成率
					List<OrgRoundVo>checkRateMonthList=new ArrayList<>();
					//当月滚动版完成率
					List<OrgRoundVo>checkRateThisMonthList=new ArrayList<>();
					//月度实际销售
					List<OrgRoundVo>monthActualSaleList=new ArrayList<>();
					//月度销售达成率
					List<OrgRoundVo>monthSaleRateList=new ArrayList<>();
	
					//首开去化率配置详情
					List<MonitorConfigDetailDto>fList=monitorConfigDetailDtoList.stream()
							.filter(x->x.getTargetCode().equals(TargetNameEnum.F.getKey())).collect(Collectors.toList());
					//月度去化率配置详情
					List<MonitorConfigDetailDto>gList=monitorConfigDetailDtoList.stream()
							.filter(x->x.getTargetCode().equals(TargetNameEnum.G.getKey())).collect(Collectors.toList());
					//新供去化率
					List<MonitorConfigDetailDto>hList=monitorConfigDetailDtoList.stream()
							.filter(x->x.getTargetCode().equals(TargetNameEnum.H.getKey())).collect(Collectors.toList());
					//库存去化率
					List<MonitorConfigDetailDto>iList=monitorConfigDetailDtoList.stream()
							.filter(x->x.getTargetCode().equals(TargetNameEnum.I.getKey())).collect(Collectors.toList());
					//长期库存去化率	
					List<MonitorConfigDetailDto>jList=monitorConfigDetailDtoList.stream()
							.filter(x->x.getTargetCode().equals(TargetNameEnum.J.getKey())).collect(Collectors.toList());
					//现房库存去化率
					List<MonitorConfigDetailDto>kList=monitorConfigDetailDtoList.stream()
							.filter(x->x.getTargetCode().equals(TargetNameEnum.K.getKey())).collect(Collectors.toList());
					
					//汇总组织机构信息和圆点
					List<OrgRoundVo>summaryOrgList=new ArrayList<>();
					//获取成功
					JSONArray retData=jsonObject.getJSONArray("retData");	
					if(retData != null) {
						for (int i = 0; i < retData.size(); i++) {
							JSONObject retDataObj=retData.getJSONObject(i);
							//首开去化率
							Double firstOpenRate=retDataObj.getDouble("firstOpenRate");
							//月度去化率
							Double monthRate=retDataObj.getDouble("MonthRate");
							//新供去化率
							Double newSupplyRemovalRate=retDataObj.getDouble("newSupplyRemovalRate");
							//库存去化率
							Double stockRemovalRate=retDataObj.getDouble("stockRemovalRate");
							//长期库存去化率	
							Double stockRemovalRatelongtime=retDataObj.getDouble("stockRemovalRatelongtime");
							//现房库存去化率
							Double saleRateExit=retDataObj.getDouble("saleRateExit");
							//年度考核指标完成率
							Double checkRateYear=retDataObj.getDouble("checkRateYear");
							//累计月度完成率
							Double checkRateMonth=retDataObj.getDouble("checkRateMonth");
							//当月滚动版完成率
							Double checkRateThisMonth=retDataObj.getDouble("checkRateThisMonth");
							//组织机构id
							String orgId1=retDataObj.getString("orgId");
							//组织机构名称
							String orgName=retDataObj.getString("orgName");
							//月度实际销售
							BigDecimal monthActualSale=retDataObj.getBigDecimal("monthActualSale");
							//月度销售达成率
							BigDecimal monthSaleRate=retDataObj.getBigDecimal("monthSaleRate");
							
							//首开去化率
							OrgRoundVo firstOpenRateVo=getOrgRoundStatus(orgName, fList, orgId1, firstOpenRate, hrOrgTypeId);
							//月度去化率
							OrgRoundVo monthRateVo=getOrgRoundStatus(orgName, gList, orgId1, monthRate, hrOrgTypeId);
							//新供去化率
							OrgRoundVo newSupplyRemovalRateVo=getOrgRoundStatus(orgName, hList, orgId1, newSupplyRemovalRate, hrOrgTypeId);
							//库存去化率
							OrgRoundVo stockRemovalRateVo=getOrgRoundStatus(orgName, iList, orgId1, stockRemovalRate, hrOrgTypeId);
							//长期库存去化率	
							OrgRoundVo stockRemovalRatelongtimeVo=getOrgRoundStatus(orgName, jList, orgId1, stockRemovalRatelongtime, hrOrgTypeId);
							//现房库存去化率
							OrgRoundVo saleRateExitVo=getOrgRoundStatus(orgName, kList, orgId1, saleRateExit, hrOrgTypeId);
		
							//下面没有圆点
							//年度考核指标完成率
							OrgRoundVo checkRateYearVo=getOrgRoundNoStatus(orgName, orgId1,checkRateYear, hrOrgTypeId);
							//累计月度完成率
							OrgRoundVo checkRateMonthVo=getOrgRoundNoStatus(orgName, orgId1,checkRateMonth, hrOrgTypeId);
							//当月滚动版完成率
							OrgRoundVo checkRateThisMonthVo=getOrgRoundNoStatus(orgName, orgId1,checkRateThisMonth, hrOrgTypeId);
							
							if(stockRemovalRateVo.getResourceStatus().equals(Constants.WARNING) 
									&& stockRemovalRatelongtimeVo.getResourceStatus().equals(Constants.WARNING)) {
								//2个条件都存在把组织机构放进去
								OrgRoundVo orgVo=getOrgRoundWarning(orgName, orgId1, hrOrgTypeId);
								summaryOrgList.add(orgVo);
							}
		
							//月度实际销售
							OrgRoundVo monthActualSaleVo=getOrgRoundNoStatus(orgName, orgId1, monthActualSale, hrOrgTypeId);
							//月度销售达成率
							OrgRoundVo monthSaleRateVo=getOrgRoundNoStatus(orgName, orgId1, monthSaleRate, hrOrgTypeId);
		
							//最后把vo放到list里面
							firstOpenRateList.add(firstOpenRateVo);
							monthRateList.add(monthRateVo);
							newSupplyRemovalRateList.add(newSupplyRemovalRateVo);
							stockRemovalRateList.add(stockRemovalRateVo);
							stockRemovalRatelongTimeList.add(stockRemovalRatelongtimeVo);
							saleRateExitList.add(saleRateExitVo);
							
							checkRateYearList.add(checkRateYearVo);
							checkRateMonthList.add(checkRateMonthVo);
							checkRateThisMonthList.add(checkRateThisMonthVo);
		
							monthActualSaleList.add(monthActualSaleVo);
							monthSaleRateList.add(monthSaleRateVo);
						}
					}
					
					//预警红黄绿
					StrUtils.compareOrder(firstOpenRateList);
					StrUtils.compareOrder(monthRateList);
					StrUtils.compareOrder(newSupplyRemovalRateList);
					StrUtils.compareOrder(stockRemovalRateList);
					StrUtils.compareOrder(stockRemovalRatelongTimeList);
					StrUtils.compareOrder(saleRateExitList);
					
					//亿元 从大到小
					checkRateYearList.sort((OrgRoundVo o1, OrgRoundVo o2)->o2.getQuotaVal().compareTo(o1.getQuotaVal()));
					checkRateMonthList.sort((OrgRoundVo o1, OrgRoundVo o2)->o2.getQuotaVal().compareTo(o1.getQuotaVal()));
					checkRateThisMonthList.sort((OrgRoundVo o1, OrgRoundVo o2)->o2.getQuotaVal().compareTo(o1.getQuotaVal()));
					monthActualSaleList.sort((OrgRoundVo o1, OrgRoundVo o2)->o2.getQuotaVal().compareTo(o1.getQuotaVal()));
					monthSaleRateList.sort((OrgRoundVo o1, OrgRoundVo o2)->o2.getQuotaVal().compareTo(o1.getQuotaVal()));
	
					//把都符合条件的组织机构信息都放进去
					saleVo.setOrgRoundList(summaryOrgList);
					//把list放到大的vo里面
					vo.setFirstOpenRateList(firstOpenRateList);
					vo.setMonthRateList(monthRateList);
					vo.setNewSupplyRemovalRateList(newSupplyRemovalRateList);
					vo.setStockRemovalRateList(stockRemovalRateList);
					vo.setStockRemovalRatelongtimeList(stockRemovalRatelongTimeList);
					vo.setSaleRateExitList(saleRateExitList);
					vo.setCheckRateYearList(checkRateYearList);
					vo.setCheckRateMonthList(checkRateMonthList);
					vo.setCheckRateThisMonthList(checkRateThisMonthList);
					vo.setMonthActualSaleList(monthActualSaleList);
					vo.setMonthSaleRateList(monthSaleRateList);
					vo.setSaleVo(saleVo);
				}else {
					//获取失败
					saveLog("获取销-明细接口失败",logUrl,title,Constants.MONITORING_CONSOLE);
				}
			}
		}else {
			log.info("获取销-明细接口失败");
			saveLog("获取销-明细接口失败",logUrl,title,Constants.MONITORING_CONSOLE);
		}
		return vo;
	}
	
	
	/**
	 * 调用数据中存明细接口
	 * @param orgId 组织机构id
	 * @param reportDate 查询截止日期
	 */
	public StockItemVo getDataStockItem(String orgId, String reportDate,List<MonitorConfigDetailDto> monitorConfigDetailDtoList,String hrOrgTypeId) {
		//切换下级类型
		hrOrgTypeId=getOrgNextType(hrOrgTypeId);
		StockItemVo vo=new StockItemVo();
		//存汇总
		StockVo stockVo=new StockVo();
		//日志路径
		String logUrl="MonitoringConsoleServiceImpl/getDataStockItem";
		//标题
		String title="获取存-明细接口";
		
		BasicAuthClient bac = new BasicAuthClient();
		String api =stockItem_url+orgId+","+reportDate;
		//拼接地址
		String url = data_middle_ground_url+api;
		String result =  bac.getData(url, data_api_key, data_api_value);
		log.info("###存-明细接口 地址： "+url);
		log.info("###存-明细接口 返回数据："+result);
		if(StrUtils.isNotEmpty(result)) {
			JSONObject jsonObject=JSONObject.parseObject(result);
			if(jsonObject!=null) {
				int retCode=jsonObject.getInteger("retCode");
				//0
				if(retCode==Constants.ZERO) {
					//库存(亿元)
					List<OrgRoundVo> storeList=new ArrayList<>();
					//已达未取(亿元)
					List<OrgRoundVo> hasNotTokenList=new ArrayList<>();
					//真实库存(亿元)
					List<OrgRoundVo> realStoreList=new ArrayList<>();
					//存销比
					List<OrgRoundVo> storeSaleRateList=new ArrayList<>();
					//长期库存占比(百分比)
					List<OrgRoundVo> storeRatelongTimeList=new ArrayList<>();
					//新增长期库存(亿元)
					List<OrgRoundVo> storeAddList=new ArrayList<>();
					//长期库存
					List<OrgRoundVo> storeLongTimeList=new ArrayList<>();
					//长期库存存销比
					List<OrgRoundVo> storeSaleRatelongtimeList=new ArrayList<>();
					//现房库存
					List<OrgRoundVo> storeExistList=new ArrayList<>();
					//现房库存存销比
					List<OrgRoundVo> storeSaleRateexitList=new ArrayList<>();
					
					//现房库存占比(百分比)
					List<OrgRoundVo> storeExistRateList=new ArrayList<>();
					//新增现房库存(亿元)
					List<OrgRoundVo> storeExistAddList=new ArrayList<>();
					
					//存销比配置详情
					List<MonitorConfigDetailDto>lList=monitorConfigDetailDtoList.stream()
							.filter(x->x.getTargetCode().equals(TargetNameEnum.L.getKey())).collect(Collectors.toList());
					//长期库存占比(百分比) 配置详情
					List<MonitorConfigDetailDto>mList=monitorConfigDetailDtoList.stream()
							.filter(x->x.getTargetCode().equals(TargetNameEnum.M.getKey())).collect(Collectors.toList());
					//长期库存存销比配置详情
					List<MonitorConfigDetailDto>oList=monitorConfigDetailDtoList.stream()
							.filter(x->x.getTargetCode().equals(TargetNameEnum.O.getKey())).collect(Collectors.toList());
					//现房库存存销比配置详情
					List<MonitorConfigDetailDto>pList=monitorConfigDetailDtoList.stream()
							.filter(x->x.getTargetCode().equals(TargetNameEnum.P.getKey())).collect(Collectors.toList());
					//新增长期库存
					List<MonitorConfigDetailDto>nList=monitorConfigDetailDtoList.stream()
							.filter(x->x.getTargetCode().equals(TargetNameEnum.N.getKey())).collect(Collectors.toList());
					
	
					//汇总组织机构信息和圆点
					List<OrgRoundVo>summaryOrgList=new ArrayList<>();
					//获取成功
					JSONArray retData=jsonObject.getJSONArray("retData");
					if (retData == null){
						return vo;
					}
					for (int i = 0; i < retData.size(); i++) {
						JSONObject retDataObj=retData.getJSONObject(i);
						//库存(亿元)
						BigDecimal store=retDataObj.getBigDecimal("store");
						//已达未取(亿元)
						BigDecimal hasNotToken=retDataObj.getBigDecimal("hasNotToken");
						//真实库存(亿元)
						BigDecimal realStore=retDataObj.getBigDecimal("realStore");
						
						//存销比
						Double storeSaleRate=retDataObj.getDouble("storeSaleRate");
						//长期库存占比(百分比)
						Double storeRatelongTime=retDataObj.getDouble("storeRatelongTime");
						//新增长期库存(亿元)
						BigDecimal storeAdd=retDataObj.getBigDecimal("storeAdd");
						
						//长期库存
						BigDecimal storeLongTime=retDataObj.getBigDecimal("storeLongTime");
						//长期库存存销比
						Double storeSaleRatelongtime=retDataObj.getDouble("storeSaleRatelongtime");
						//现房库存
						BigDecimal storeExist=retDataObj.getBigDecimal("storeExist");
						//现房库存存销比
						Double storeSaleRateexit=retDataObj.getDouble("storeSaleRateexit");
						//组织机构id
						String orgId1=retDataObj.getString("orgId");
						//组织机构名称
						String orgName=retDataObj.getString("orgName");
						//现房库存占比(百分比)
						Double storeExistRate=retDataObj.getDouble("storeExistRate");
						//新增现房库存(亿元)
						BigDecimal storeExistAdd=retDataObj.getBigDecimal("storeExistAdd");
						
						//库存(亿元)
						OrgRoundVo storeVo=getOrgRoundBigDecimalNoStatus(orgName, orgId1, store, hrOrgTypeId);
						//已达未取(亿元)
						OrgRoundVo hasNotTokenVo=getOrgRoundBigDecimalNoStatus(orgName, orgId1, hasNotToken, hrOrgTypeId);
						//真实库存(亿元)
						OrgRoundVo realStoreVo=getOrgRoundBigDecimalNoStatus(orgName, orgId1, realStore, hrOrgTypeId);
						
						//长期库存
						OrgRoundVo storeLongTimeVo=getOrgRoundBigDecimalNoStatus(orgName, orgId1,storeLongTime, hrOrgTypeId);
						//现房库存
						OrgRoundVo storeExistVo=getOrgRoundBigDecimalNoStatus(orgName, orgId1,storeExist, hrOrgTypeId);
						//现房库存占比(百分比)
						OrgRoundVo storeExistRateVo=getOrgRoundNoStatus(orgName, orgId1, storeExistRate, hrOrgTypeId);
						//新增现房库存(亿元)
						OrgRoundVo storeExistAddVo=getOrgRoundBigDecimalNoStatus(orgName, orgId1, storeExistAdd, hrOrgTypeId);
						
						//存销比
						OrgRoundVo storeSaleRateVo=getOrgRoundStatus(orgName, lList, orgId1, storeSaleRate, hrOrgTypeId);
						//长期库存占比(百分比)
						OrgRoundVo storeRatelongTimeVo=getOrgRoundStatus(orgName, mList, orgId1, storeRatelongTime, hrOrgTypeId);
						//长期库存存销比
						OrgRoundVo storeSaleRatelongtimeVo=getOrgRoundStatus(orgName, oList, orgId1, storeSaleRatelongtime, hrOrgTypeId);
						//现房库存存销比
						OrgRoundVo storeSaleRateexitVo=getOrgRoundStatus(orgName, pList, orgId1, storeSaleRateexit, hrOrgTypeId);
						//新增长期库存(亿元)
						OrgRoundVo storeAddVo=getOrgRoundBigDecimalStatus(orgName,nList, orgId1, storeAdd, hrOrgTypeId);
						
						
							
						if(storeSaleRateVo.getResourceStatus().equals(Constants.WARNING) 
								&& storeRatelongTimeVo.getResourceStatus().equals(Constants.WARNING)
								&& storeSaleRatelongtimeVo.getResourceStatus().equals(Constants.WARNING)
								) {
							//2个条件都存在把组织机构放进去
							OrgRoundVo orgVo=getOrgRoundWarning(orgName, orgId1, hrOrgTypeId);
							summaryOrgList.add(orgVo);
						}
						
						//最后把vo放到list里面
						storeList.add(storeVo);
						hasNotTokenList.add(hasNotTokenVo);
						realStoreList.add(realStoreVo);
						storeSaleRateList.add(storeSaleRateVo);
						storeRatelongTimeList.add(storeRatelongTimeVo);
						storeAddList.add(storeAddVo);
						storeLongTimeList.add(storeLongTimeVo);
						storeSaleRatelongtimeList.add(storeSaleRatelongtimeVo);
						storeExistList.add(storeExistVo);
						storeSaleRateexitList.add(storeSaleRateexitVo);
						storeExistRateList.add(storeExistRateVo);
						storeExistAddList.add(storeExistAddVo);
					}
					
					
					//预警红黄绿
					StrUtils.compareOrder(storeSaleRateList);
					StrUtils.compareOrder(storeSaleRatelongtimeList);
					StrUtils.compareOrder(storeSaleRateexitList);
					StrUtils.compareOrder(storeRatelongTimeList);
					StrUtils.compareOrder(storeAddList);
					
					//亿元 从大到小
					storeList.sort((OrgRoundVo o1, OrgRoundVo o2)->o2.getQuotaVal().compareTo(o1.getQuotaVal()));
					hasNotTokenList.sort((OrgRoundVo o1, OrgRoundVo o2)->o2.getQuotaVal().compareTo(o1.getQuotaVal()));
					realStoreList.sort((OrgRoundVo o1, OrgRoundVo o2)->o2.getQuotaVal().compareTo(o1.getQuotaVal()));
					storeLongTimeList.sort((OrgRoundVo o1, OrgRoundVo o2)->o2.getQuotaVal().compareTo(o1.getQuotaVal()));
					storeExistList.sort((OrgRoundVo o1, OrgRoundVo o2)->o2.getQuotaVal().compareTo(o1.getQuotaVal()));
					
					storeExistRateList.sort((OrgRoundVo o1, OrgRoundVo o2)->o2.getQuotaVal().compareTo(o1.getQuotaVal()));
					storeExistAddList.sort((OrgRoundVo o1, OrgRoundVo o2)->o2.getQuotaVal().compareTo(o1.getQuotaVal()));
					
					//把都符合条件的组织机构信息都放进去
					stockVo.setOrgRoundList(summaryOrgList);
					
					//把list放到大的vo里面
					vo.setStoreSaleRateList(storeSaleRateList);
					vo.setStoreSaleRatelongtimeList(storeSaleRatelongtimeList);
					vo.setStoreSaleRateexitList(storeSaleRateexitList);
					vo.setStoreRatelongTimeList(storeRatelongTimeList);
					vo.setStoreList(storeList);
					vo.setHasNotTokenList(hasNotTokenList);
					vo.setRealStoreList(realStoreList);
					vo.setStoreAddList(storeAddList);
					vo.setStoreLongTimeList(storeLongTimeList);
					vo.setStoreExistList(storeExistList);
					vo.setStoreExistRateList(storeExistRateList);
					vo.setStoreExistAddList(storeExistAddList);
					
					vo.setStockVo(stockVo);
				}else {
					//获取失败
					saveLog("获取存-明细接口失败",logUrl,title,Constants.MONITORING_CONSOLE);
				}
			}
		}else {
			log.info("获取存-明细接口失败");
			saveLog("获取存-明细接口失败",logUrl,title,Constants.MONITORING_CONSOLE);
		}
		return vo;
	}
	
	
	
	/**
	 * 调用数据中结-明细接口
	 * @param orgId 组织机构id
	 * @param reportDate 查询截止日期
	 */
	public StatementItemVo getDataStatementItem(String orgId, String reportDate,List<MonitorConfigDetailDto> monitorConfigDetailDtoList,String hrOrgTypeId) {
		//切换下级类型
		hrOrgTypeId=getOrgNextType(hrOrgTypeId);
		StatementItemVo vo=new StatementItemVo();
		//结汇总
		StatementVo statementVo=new StatementVo();
		//日志路径
		String logUrl="MonitoringConsoleServiceImpl/getDataStatementItem";
		//标题
		String title="获取结-明细接口";
		
		BasicAuthClient bac = new BasicAuthClient();
		String api =statementItem_url+orgId+","+reportDate;
		//拼接地址
		String url = data_middle_ground_url+api;
		String result =  bac.getData(url, data_api_key, data_api_value);
		log.info("###结-明细接口 地址： "+url);
		log.info("###结-明细接口 返回数据："+result);
		if(StrUtils.isNotEmpty(result)) {
			JSONObject jsonObject=JSONObject.parseObject(result);
			//截取月份
			String month=reportDate.substring(4,6);
			if(jsonObject!=null) {
				int retCode=jsonObject.getInteger("retCode");
				//0
				if(retCode==Constants.ZERO) {
					//结转去化率(百分比)
					List<OrgRoundVo> statementRateList=new ArrayList<>();
					//业绩锁定率(百分比)
					List<OrgRoundVo> achievementLockRateList=new ArrayList<>();
					//可结转资源(亿元)
					List<OrgRoundVo> statementValueList=new ArrayList<>();
					//结转去化率(上半年)配置详情
					List<MonitorConfigDetailDto>qList=new ArrayList<>();
	
					// 结转去化率 1-6月取上半年
					if(Integer.parseInt(month) <= Constants.SIX) {
						qList = monitorConfigDetailDtoList.stream()
								.filter(x -> x.getTargetCode().equals(TargetNameEnum.Q.getKey()))
								.collect(Collectors.toList());
					}
					// 结转去化率 7-12取下半年
					if(Integer.parseInt(month) >= Constants.SEVEN) {
						qList = monitorConfigDetailDtoList.stream()
								.filter(x -> x.getTargetCode().equals(TargetNameEnum.R.getKey()))
								.collect(Collectors.toList());
					}
	
					//汇总组织机构信息和圆点
					List<OrgRoundVo>summaryOrgList=new ArrayList<>();
					//获取成功
					JSONArray retData=jsonObject.getJSONArray("retData");
					if (retData == null){
						return vo;
					}
					for (int i = 0; i < retData.size(); i++) {
						JSONObject retDataObj=retData.getJSONObject(i);
						//结转去化率(百分比)
						Double statementRate=retDataObj.getDouble("statementRate");
						//业绩锁定率(百分比)
						Double achievementLockRate=retDataObj.getDouble("achievementLockRate");
						//可结转资源(亿元)
						Double statementValue=retDataObj.getDouble("statementValue");
						//组织机构id
						String orgId1=retDataObj.getString("orgId");
						//组织机构名称
						String orgName=retDataObj.getString("orgName");
	
						//业绩锁定率(百分比)
						OrgRoundVo achievementLockRateVo=getOrgRoundNoStatus(orgName, orgId1,achievementLockRate, hrOrgTypeId);
						//可结转资源(亿元)
						OrgRoundVo statementValueVo=getOrgRoundNoStatus(orgName, orgId1, statementValue, hrOrgTypeId);
						//结转去化率(百分比)
						OrgRoundVo statementRateVo=getOrgRoundStatus(orgName, qList, orgId1, statementRate, hrOrgTypeId);
								
						if(statementRateVo.getResourceStatus().equals(Constants.WARNING)) {
							//条件都存在把组织机构放进去
							OrgRoundVo orgVo=getOrgRoundWarning(orgName, orgId1, hrOrgTypeId);
							summaryOrgList.add(orgVo);
						}
						
						//最后把vo放到list里面
						statementRateList.add(statementRateVo);
						achievementLockRateList.add(achievementLockRateVo);
						statementValueList.add(statementValueVo);
					}
					
					
					//预警红黄绿
					StrUtils.compareOrder(statementRateList);
	
					//亿元 从大到小
					achievementLockRateList.sort((OrgRoundVo o1, OrgRoundVo o2)->o2.getQuotaVal().compareTo(o1.getQuotaVal()));
					statementValueList.sort((OrgRoundVo o1, OrgRoundVo o2)->o2.getQuotaVal().compareTo(o1.getQuotaVal()));
					
					//把都符合条件的组织机构信息都放进去
					statementVo.setOrgRoundList(summaryOrgList);
					
					//把list放到大的vo里面
					vo.setStatementRateList(statementRateList);
					vo.setAchievementLockRateList(achievementLockRateList);
					vo.setStatementValueList(statementValueList);
					vo.setStatementVo(statementVo);
				}else {
					//获取失败
					saveLog("获取结-明细接口失败",logUrl,title,Constants.MONITORING_CONSOLE);
				}
			}
		}else {
			log.info("获取结-明细接口失败");
			saveLog("获取结-明细接口失败",logUrl,title,Constants.MONITORING_CONSOLE);
		}
		return vo;
	}
	
	/**
     * 调用数据中回-明细接口
     *
     * @param orgId      组织机构id
     * @param reportDate 查询截止日期
     */
    public ReturnItemVo getDataReturnItem(String orgId, String reportDate, List<MonitorConfigDetailDto> monitorConfigDetailDtoList, String hrOrgTypeId) {
        //切换下级类型
        hrOrgTypeId = getOrgNextType(hrOrgTypeId);

        //回-详情
        ReturnItemVo vo = new ReturnItemVo();
        //回-汇总
        ReturnVo returnVo = new ReturnVo();
        //汇总组织机构信息和圆点
        List<OrgRoundVo> summaryOrgList = new ArrayList<>();

        //获取监控台-回数据
        List<SupervisoryConsoleReturnDetail> returnDetailList = supervisoryConsoleReturnDetailMapper.getReturnDetailByParentId(orgId, reportDate);
        //年度签约回款率
        List<OrgRoundVo> returnYearSignList = new ArrayList<>();
        //年度综合回款率
        List<OrgRoundVo> returnAllYearSignList = new ArrayList<>();
        //滚动综合回款率
        List<OrgRoundVo> rollReturnList = new ArrayList<>();

        for (SupervisoryConsoleReturnDetail tSupervisoryConsoleReturnDetail : returnDetailList) {
            //年度签约回款率
            Double returnYearSign = tSupervisoryConsoleReturnDetail.getReturnYearSign();
            //年度综合回款率
            Double returnAllYearSign = tSupervisoryConsoleReturnDetail.getReturnAllYearSign();
            //滚动综合回款率
            Double rollReturn = tSupervisoryConsoleReturnDetail.getRollReturn();
            //组织机构id
            String orgId1 = tSupervisoryConsoleReturnDetail.getOrgdepid();
            //组织机构名称
            String orgName = tSupervisoryConsoleReturnDetail.getOrgname();

            //回配置详情
            List<MonitorConfigDetailDto> rList = monitorConfigDetailDtoList.stream()
                    .filter(x -> x.getTargetCode().equals(TargetNameEnum.S.getKey())).collect(Collectors.toList());

            //年度签约回款率百分比)
            OrgRoundVo returnYearSignVo = getOrgRoundStatus(orgName, rList, orgId1, returnYearSign, hrOrgTypeId);
            //年度综合回款率(亿元)
            OrgRoundVo returnAllYearSignVo = getOrgRoundStatus(orgName, rList, orgId1, returnAllYearSign, hrOrgTypeId);
            //滚动综合回款率(百分比)
            OrgRoundVo rollReturnVo = getOrgRoundStatus(orgName, rList, orgId1, rollReturn, hrOrgTypeId);

            if (returnYearSignVo.getResourceStatus().equals(Constants.WARNING)
                    && returnAllYearSignVo.getResourceStatus().equals(Constants.WARNING)
                    && rollReturnVo.getResourceStatus().equals(Constants.WARNING)
            ) {
                //3个条件都存在把组织机构放进去
                OrgRoundVo orgVo = getOrgRoundWarning(orgName, orgId1, hrOrgTypeId);
                summaryOrgList.add(orgVo);
            }

            //最后把vo放到list里面
            returnYearSignList.add(returnYearSignVo);
            returnAllYearSignList.add(returnAllYearSignVo);
            rollReturnList.add(rollReturnVo);
        }
        //预警红黄绿
        StrUtils.compareOrder(returnYearSignList);
        StrUtils.compareOrder(returnAllYearSignList);
        StrUtils.compareOrder(rollReturnList);
        //把都符合条件的组织机构信息都放进去
        returnVo.setOrgRound(summaryOrgList);
        //把list放到大的vo里面
		vo.setReturnYearSignList(returnYearSignList);
        vo.setReturnAllYearSignList(returnAllYearSignList);
        vo.setRollReturnList(rollReturnList);
        vo.setReturnVo(returnVo);
        return vo;
    }
	
	/**
	 * 获取组织机构的数量
	 * @param map
	 * @param list
	 */
	public void getOrgNum(Map<String,Integer>map,List<OrgRoundVo>list) {
		if(CollectionUtils.isNotEmpty(list)) {
			for (OrgRoundVo orv : list) {
				if(map.containsKey(orv.getOrgName())) {
					int num=map.get(orv.getOrgName());
					num++;
					map.put(orv.getOrgName(), num);
				}else {
					map.put(orv.getOrgName(), 1);
				}
			}
		}
	}
	
	/**
	 * 根据组织机构类型 返回下级类型
	 * @param hrOrgTypeId
	 */
	public String getOrgNextType(String hrOrgTypeId) {
		if(hrOrgTypeId.equals(HrOrgTypeEunm.ORG_11.getKey())) {
			return HrOrgTypeEunm.ORG_20.getKey();
		}
		if(hrOrgTypeId.equals(HrOrgTypeEunm.ORG_20.getKey())) {
			return HrOrgTypeEunm.ORG_21.getKey();
		}
		if(hrOrgTypeId.equals(HrOrgTypeEunm.ORG_21.getKey())) {
			return HrOrgTypeEunm.ORG_31.getKey();
		}
		if(hrOrgTypeId.equals(HrOrgTypeEunm.ORG_31.getKey())) {
			return HrOrgTypeEunm.ORG_32.getKey();
		}
		return "";
	}
	
	/**
	 * 获取监控台用户的数据权限
	 */
	@Override
	public List<ProjectByStagesDto> getMonitoringUserDataPermissions(String userId) {
		//1.查询用户是否存在角色
		List<SysUserRole>roleList=sysUserRoleMapper.selectByUserId(userId);
		if(CollectionUtils.isNotEmpty(roleList)) {
			return getUserRoleV3(roleList);
		}else {
			//2.查询用户是否设置岗位组 岗位权限
			return getUserPositionV3(userId);
		}
	}
	
	
	/**
	 * 优化用户角色,获取角色的组织机构信息->数据权限 项目分期
	 * @param roleList
	 */
	public List<ProjectByStagesDto> getUserRoleV3(List<SysUserRole>roleList) {
		List<ProjectByStagesDto> dtoList=new ArrayList<>();
		HashSet<ProjectByStagesDto>list=new HashSet<>();
		List<String> roleIds=new ArrayList<>();
		for (SysUserRole role : roleList) {
			String roleId=role.getRoleId();
			roleIds.add(roleId);
		}
		//旭辉集团的 全部查出来
		List<String>xhIds=projectByStagesMapper.selectStagesId(roleIds, HrOrgTypeEunm.ORG_11.getKey());		
		//区域的id 全部查出来
		List<String>regionIds=projectByStagesMapper.selectStagesId(roleIds, HrOrgTypeEunm.ORG_20.getKey());
		//城市公司的id 全部查出来
		List<String>cityIds=projectByStagesMapper.selectStagesId(roleIds, HrOrgTypeEunm.ORG_21.getKey());
		//直管项目的id 全部查出来
		List<String>tubeIds=projectByStagesMapper.selectStagesId(roleIds, HrOrgTypeEunm.ORG_23.getKey());
		//项目的id 全部查出来
		List<String>projectIds=projectByStagesMapper.selectStagesId(roleIds, HrOrgTypeEunm.ORG_31.getKey());
		
		List<String>orgdepIds=new ArrayList<>();
		orgdepIds.addAll(xhIds);
		orgdepIds.addAll(regionIds);
		orgdepIds.addAll(cityIds);
		orgdepIds.addAll(tubeIds);
		orgdepIds.addAll(projectIds);
		
		if(CollectionUtils.isNotEmpty(orgdepIds)) {
			List<ProjectByStagesDto>orgList=new ArrayList<>();
			orgList=projectByStagesMapper.selectByOrgdepids(orgdepIds);
			list.addAll(orgList);
		}

		if(CollectionUtils.isNotEmpty(regionIds)) { 
			//区域不为空 获取集团
			List<String>orgIds=new ArrayList<>();
			orgIds.add(Constants.XUHUI_GROUP);
			List<ProjectByStagesDto>regionList=projectByStagesMapper.selectByOrgdepids(orgIds);
			list.addAll(regionList);
		}
		if(CollectionUtils.isNotEmpty(cityIds)) {
			//根据城市id获取区域信息
			List<ProjectByStagesDto>regionList=projectByStagesMapper.selectOrgParentList(cityIds);
			list.addAll(regionList);
		}
		if(CollectionUtils.isNotEmpty(tubeIds)) {
			//根据直管项目id获取父级信息
			List<ProjectByStagesDto>cityList=projectByStagesMapper.selectOrgParentList(tubeIds);
			list.addAll(cityList);
		}
		if(CollectionUtils.isNotEmpty(projectIds)) {
			//根据项目id获取城市公司信息
			List<ProjectByStagesDto>cityList=projectByStagesMapper.selectOrgParentList(projectIds);
			List<String>cityStr=new ArrayList<>();
			for (ProjectByStagesDto c : cityList) {
				cityStr.add(c.getOrgdepid());
			}
			//根据城市公司id获取区域信息
			List<ProjectByStagesDto>regionList=projectByStagesMapper.selectOrgParentList(cityStr);
			list.addAll(regionList);
			list.addAll(cityList);
		}
		dtoList.addAll(list);
		return dtoList;
	}
	
	
	/**
	 * 优化用户岗位,岗位组,获取岗位,岗位组的组织机构信息->项目分期树
	 * 数据权限到岗位->设置自动授权后就有他的岗位组数据权限
	 * @param roleList
	 */
	public List<ProjectByStagesDto> getUserPositionV3(String userId) {
		List<ProjectByStagesDto> dtoList=new ArrayList<>();
		// 根据用户id或者用户信息
		IdmUser user=idmUserMapper.selectByUserName(userId);
		HashSet<ProjectByStagesDto>list=new HashSet<>();
		List<ProjectByStagesDto>groupList=new ArrayList<>();
		List<String>positionIds=new ArrayList<>();
		List<ProjectByStagesDto>positionList=new ArrayList<>();
		if(user!=null) {
			//查询有没有兼职岗位
			if(StringUtils.isNotEmpty(user.getParttimepost())) {
				//5.查询是否兼职岗位授权
				String [] post=user.getParttimepost().split(";");
				for (String string : post) {
					positionIds.add(string);
				}
			}
			if(StringUtils.isNotEmpty(user.getPositionid())) {
				positionIds.add(user.getPositionid());
			}
			//根据兼职岗位查询岗位组
			List<String>positionGroupIds=new ArrayList<>();
			if(CollectionUtils.isNotEmpty(positionIds)) {
				positionGroupIds=idmPositionMapper.selectPositionGroupIds(positionIds);
			}
			
			if(StringUtils.isNotEmpty(user.getIDMJobdefid())) {
				positionGroupIds.add(user.getIDMJobdefid());
				
			}
			//根据多个岗位组id查询只授权的岗位id集合
			List<String> positionIdList=sysPositionGroupAuthorizeMapper.selectByPositionGroupIds(positionGroupIds,positionIds);
			for (String posiId : positionIdList) {
				//只查授权的岗位组下的岗位id
				List<String> orgids=getGroupOrgIds(posiId);
				if(CollectionUtils.isNotEmpty(orgids)) {
					List<ProjectByStagesDto>psdList=getPositionGroupList(orgids);
					groupList.addAll(psdList);
				}
			}
			positionList=getPositionListV3(positionIds);
		}
		list.addAll(groupList);
		list.addAll(positionList);
		dtoList.addAll(list);
		return dtoList;
	}
	

	/**
	 * 优化岗位,兼职岗位->数据权限
	 * @param pbs
	 * @return
	 */
	public List<ProjectByStagesDto> getPositionListV3(List<String>positionIds) {
		List<ProjectByStagesDto> dtoList=new ArrayList<>();
		if(CollectionUtils.isEmpty(positionIds)) {
			return dtoList;
		}
		HashSet<ProjectByStagesDto>list=new HashSet<>();
		
		//旭辉集团的 全部查出来
		List<String>xhIds=projectByStagesMapper.selectStagesByPositionIds(positionIds, HrOrgTypeEunm.ORG_11.getKey());
				
		//区域的id 全部查出来
		List<String>regionIds=projectByStagesMapper.selectStagesByPositionIds(positionIds, HrOrgTypeEunm.ORG_20.getKey());
		//城市公司的id 全部查出来
		List<String>cityIds=projectByStagesMapper.selectStagesByPositionIds(positionIds, HrOrgTypeEunm.ORG_21.getKey());
		//直管项目的id 全部查出来
		List<String>tubeIds=projectByStagesMapper.selectStagesByPositionIds(positionIds, HrOrgTypeEunm.ORG_23.getKey());
		//项目的id 全部查出来
		List<String>projectIds=projectByStagesMapper.selectStagesByPositionIds(positionIds, HrOrgTypeEunm.ORG_31.getKey());
		
		List<String>orgdepIds=new ArrayList<>();
		orgdepIds.addAll(xhIds);
		orgdepIds.addAll(regionIds);
		orgdepIds.addAll(cityIds);
		orgdepIds.addAll(tubeIds);
		orgdepIds.addAll(projectIds);
		if(CollectionUtils.isNotEmpty(orgdepIds)) {
			List<ProjectByStagesDto>orgList=new ArrayList<>();
			orgList=projectByStagesMapper.selectByOrgdepids(orgdepIds);
			list.addAll(orgList);
		}

		if(CollectionUtils.isNotEmpty(regionIds)) { 
			//区域不为空 获取集团
			List<String>orgIds=new ArrayList<>();
			orgIds.add(Constants.XUHUI_GROUP);
			List<ProjectByStagesDto>regionList=projectByStagesMapper.selectByOrgdepids(orgIds);
			list.addAll(regionList);
		}
		if(CollectionUtils.isNotEmpty(cityIds)) {
			//根据城市id获取区域信息
			List<ProjectByStagesDto>regionList=projectByStagesMapper.selectOrgParentList(cityIds);
			list.addAll(regionList);
		}
		if(CollectionUtils.isNotEmpty(tubeIds)) {
			//根据直管项目id获取父级信息
			List<ProjectByStagesDto>cityList=projectByStagesMapper.selectOrgParentList(tubeIds);
			list.addAll(cityList);
		}
		if(CollectionUtils.isNotEmpty(projectIds)) {
			//根据项目id获取城市公司信息
			List<ProjectByStagesDto>cityList=projectByStagesMapper.selectOrgParentList(projectIds);
			List<String>cityStr=new ArrayList<>();
			for (ProjectByStagesDto c : cityList) {
				cityStr.add(c.getOrgdepid());
			}
			//根据城市公司id获取区域信息
			List<ProjectByStagesDto>regionList=projectByStagesMapper.selectOrgParentList(cityStr);
			list.addAll(regionList);
			list.addAll(cityList);
		}
		dtoList.addAll(list);
		return dtoList;
	}
	
	/**
	 * 获取自动授权的岗位组的组织机构id
	 * @param orgnofullpath
	 * @return
	 */
	public List<String> getGroupOrgIds(String positionId) {
		List<String>orgids=new ArrayList<>();
		String belongDepFullNo=idmPositionMapper.selectBelongDepFullNoList(positionId);
		if(StringUtils.isEmpty(belongDepFullNo)) {
			return orgids;
		}
		String []path=belongDepFullNo.split("-");
		//根据岗位id获取部门全路径信息
		String belongDepFullName=idmPositionMapper.selectBelongDepFullNameList(positionId);
		if(belongDepFullName.contains("期")) {
			//不在我们本地数据库的分期 不显示出来
			String stagesId=path[belongDepFullNo.split("-").length-1];
			ProjectByStagesDto bb =projectByStagesMapper.selectByOrgdepid(stagesId);
			if(null==bb) {
				return orgids;
			}
		}

		for (int i=path.length-1;i>=0;i--) {
			String str=path[i];
			ProjectByStagesDto bb =projectByStagesMapper.selectByOrgdepid(str);
			if(bb!=null) {
				if(StringUtils.isNotEmpty(bb.getHrOrgTypeId())) {
					if(bb.getHrOrgTypeId().equals(HrOrgTypeEunm.ORG_31.getKey())) {
						orgids.add(str);
						break;
					}else if(bb.getHrOrgTypeId().equals(HrOrgTypeEunm.ORG_23.getKey())) {
						orgids.add(str);
						break;
					}else if(bb.getHrOrgTypeId().equals(HrOrgTypeEunm.ORG_21.getKey())) {
						orgids.add(str);
						break;
					}else if(bb.getHrOrgTypeId().equals(HrOrgTypeEunm.ORG_20.getKey())) {
						orgids.add(str);
						break;
					}else if(bb.getHrOrgTypeId().equals(HrOrgTypeEunm.ORG_11.getKey())) {
						orgids.add(str);
						break;
					}
				}
			}
		}
		return orgids;
	}
	
	
	/**
	 * 优化岗位组->数据权限-》自动授权的组织机构权限
	 * @param pbs
	 * @return
	 */
	public List<ProjectByStagesDto> getPositionGroupList(List<String>positionIds) {
		List<ProjectByStagesDto> dtoList=new ArrayList<>();
		if(positionIds.size()==0) {
			return dtoList;
		}
		HashSet<ProjectByStagesDto>list=new HashSet<>();
		
		//旭辉集团的 全部查出来
		List<String>xhIds=projectByStagesMapper.selectStagesByPositionGroupIds(positionIds, HrOrgTypeEunm.ORG_11.getKey());
				
		//区域的id 全部查出来
		List<String>regionIds=projectByStagesMapper.selectStagesByPositionGroupIds(positionIds, HrOrgTypeEunm.ORG_20.getKey());
		//城市公司的id 全部查出来
		List<String>cityIds=projectByStagesMapper.selectStagesByPositionGroupIds(positionIds, HrOrgTypeEunm.ORG_21.getKey());
		//直管项目的id 全部查出来
		List<String>tubeIds=projectByStagesMapper.selectStagesByPositionGroupIds(positionIds, HrOrgTypeEunm.ORG_23.getKey());
		//项目的id 全部查出来
		List<String>projectIds=projectByStagesMapper.selectStagesByPositionGroupIds(positionIds, HrOrgTypeEunm.ORG_31.getKey());
		
		List<String>orgdepIds=new ArrayList<>();
		orgdepIds.addAll(xhIds);
		orgdepIds.addAll(regionIds);
		orgdepIds.addAll(cityIds);
		orgdepIds.addAll(tubeIds);
		orgdepIds.addAll(projectIds);
		if(CollectionUtils.isNotEmpty(orgdepIds)) {
			List<ProjectByStagesDto>orgList=new ArrayList<>();
			orgList=projectByStagesMapper.selectByOrgdepids(orgdepIds);
			list.addAll(orgList);
		}

		if(CollectionUtils.isNotEmpty(regionIds)) { 
			//区域不为空 获取集团
			List<String>orgIds=new ArrayList<>();
			orgIds.add(Constants.XUHUI_GROUP);
			List<ProjectByStagesDto>regionList=projectByStagesMapper.selectByOrgdepids(orgIds);
			list.addAll(regionList);
		}
		if(CollectionUtils.isNotEmpty(cityIds)) {
			//根据城市id获取区域信息
			List<ProjectByStagesDto>regionList=projectByStagesMapper.selectOrgParentList(cityIds);
			list.addAll(regionList);
		}
		if(CollectionUtils.isNotEmpty(tubeIds)) {
			//根据直管项目id获取父级信息
			List<ProjectByStagesDto>cityList=projectByStagesMapper.selectOrgParentList(tubeIds);
			list.addAll(cityList);
		}
		if(CollectionUtils.isNotEmpty(projectIds)) {
			//根据项目id获取城市公司信息
			List<ProjectByStagesDto>cityList=projectByStagesMapper.selectOrgParentList(projectIds);
			List<String>cityStr=new ArrayList<>();
			for (ProjectByStagesDto c : cityList) {
				cityStr.add(c.getOrgdepid());
			}
			//根据城市公司id获取区域信息
			List<ProjectByStagesDto>regionList=projectByStagesMapper.selectOrgParentList(cityStr);
			list.addAll(regionList);
			list.addAll(cityList);
		}
		dtoList.addAll(list);
		return dtoList;
	}
	
	

	/**
     * 发送预警提醒
     */
	@Override
	public String warningReminderSave(String reportDate) {
		log.info("###监控台预警提醒日志保存开始： "+LocalDateTime.now());
		//查询集团id
		String groupId=Constants.XUHUI_GROUP;
		List<ProjectByStagesDto> orgList = projectByStagesMapper.selectAllList();
		List<MonitorWarningConfig> warningConfigList = monitorWarningConfigMapper.selectAllList();
		List<MonitorConfigDetailDto> groupMonitorConfigDetailList=getDetailByOrgId(groupId,HrOrgTypeEunm.ORG_11.getKey()); 
		List<MonitorWarningLog> monitorWarningLogList = Collections.synchronizedList(new ArrayList<>());
	    //储发送预警信息
		sendStore(groupId, reportDate, orgList,groupMonitorConfigDetailList,warningConfigList,monitorWarningLogList);
		//产发送预警信息
		sendProduce(groupId, reportDate, orgList,groupMonitorConfigDetailList,warningConfigList,monitorWarningLogList);
		//销发送预警信息
		sendSale(groupId, reportDate, orgList,groupMonitorConfigDetailList,warningConfigList,monitorWarningLogList);
		//存发送预警信息
		sendStock(groupId, reportDate,orgList,groupMonitorConfigDetailList,warningConfigList,monitorWarningLogList);
		//结发送预警信息
		sendStatement(groupId, reportDate, orgList,groupMonitorConfigDetailList,warningConfigList,monitorWarningLogList);
		//保存预警日志
		monitorWarningLogList = monitorWarningLogList.stream().filter(x-> x != null).collect(Collectors.toList());
		if(CollectionUtils.isNotEmpty(monitorWarningLogList)) {
			monitorWarningLogMapper.removeData(reportDate);
			monitorWarningLogMapper.insertBatch(monitorWarningLogList);
		}
		saveLog(reportDate+"保存预警提醒日志："+monitorWarningLogList.size(), "","预警提醒日志保存",Constants.MONITORING_CONSOLE);
		log.info("###监控台预警提醒日志保存结束： "+LocalDateTime.now());
		return "发送完毕"+monitorWarningLogList.size();
	}
	
	@Override
	public void warningReminderSend(String reportDate, String code) {
		log.info("###监控台预警提醒发送开始： "+LocalDateTime.now());
		List<MonitorWarningLog> monitorWarningLogList = monitorWarningLogMapper.selectByYearMonthAndCode(reportDate,code);
		List<IdmUser> userList = idmUserMapper.selectUserList();
		if(CollectionUtils.isNotEmpty(monitorWarningLogList)) {
			for(MonitorWarningLog log : monitorWarningLogList) {
				String todoOrgType = TodoOrgTypeEnum.getKey(log.getOrgType());
				String orgId="";
				String groupId=log.getGroupId();
				String regionId=log.getRegionId();
				String cityId=log.getCityId();
				String projectId=log.getProjectId();
				String content = log.getContent();
				String condition = log.getCondition();
				String dimensionCode = log.getDimensionCode();
				String dimensionName =log.getDimensionName();
				if(todoOrgType.equals(TodoOrgTypeEnum.ONE.getKey())) {
					//集团
					orgId=groupId;
				}
				if(todoOrgType.equals(TodoOrgTypeEnum.TWO.getKey())) {
					//区域加上集团总部id
					orgId=regionId;
				}	
				if(todoOrgType.equals(TodoOrgTypeEnum.THREE.getKey())) {
					//城市公司
					orgId=cityId;
				}
				if(todoOrgType.equals(TodoOrgTypeEnum.FOUR.getKey())) {
					//项目
					orgId=projectId;
				}
				PortalTodoBo doorTodoBo=new PortalTodoBo();
				doorTodoBo.setTitle(content);
				//任务类型，待办列表中显示在主题前面的中括号中，表示提醒审批人待审批的是什么。如“转交”，“驳回”，“合同审批”等，最多用四个字来总结
				//预警提醒
				doorTodoBo.setTodoType(TodoTypeCodeEnum.EARLY_WARNING.getValue());
				//任务类型code
				doorTodoBo.setTodoTypeCode(TodoTypeCodeEnum.EARLY_WARNING.getKey());
				//待办组织类型 
				doorTodoBo.setOrgType(todoOrgType);
		        //集团id
		        doorTodoBo.setGroupId(groupId);
		        //区域或事业部id
		        doorTodoBo.setRegionId(regionId);
		        //城市公司id
		        doorTodoBo.setCityId(cityId);
		        //项目id
		        doorTodoBo.setProjectId(projectId);
		        //待办说明
		        doorTodoBo.setContent(content);

				//添加监控预警记录表
				String monitorWarningId=insertMonitorWarning(todoOrgType,
						orgId, dimensionCode, dimensionName, condition, reportDate);
				//提醒人员
				String reminderStaff=log.getRemindAccount();
				//添加监控预警指标表（记录基于维度预警的指标明细）
				String warningPortalId=insertMonitorWarningQuota(dimensionCode, dimensionName,
						reminderStaff, content, monitorWarningId);
				
				IdmUser idmUser = getIdmUser(log.getRemindAccount(),userList);
				//门户待办id
		        String instanceId=commonService.sendMessagePortalTodoByUser(Constants.SYS, doorTodoBo,idmUser);
		        //添加监控预警门户提醒关系表
		        insertMonitorWarningPortal(warningPortalId, instanceId);
			}
		}
		
		log.info("###监控台预警提醒发送开始： "+LocalDateTime.now());
		saveLog(reportDate+"发送预警提醒日志："+monitorWarningLogList.size(), "","预警提醒日志发送",Constants.MONITORING_CONSOLE);
	}


	private IdmUser getIdmUser(String remindAccount,List<IdmUser> userList) {
		for(IdmUser user : userList) {
			if("1".equals(user.getUserstatus()) && user.getAlias().equals(remindAccount)) {
				return user;
			}
		}
		return new IdmUser();
	}


	/**
	 * 发送储预警信息,没城市和项目
	 * 静态储备周期＜2.0且动态储备周期＜1.5
	 * @param groupId
	 * @param regionList
	 */
	public void sendStore(String groupId,String reportDate,List<ProjectByStagesDto> orgList,List<MonitorConfigDetailDto> groupMonitorConfigDetailList,List<MonitorWarningConfig> warningConfigList,List<MonitorWarningLog> monitorWarningLogList) {
		//调用数据中台储-汇总接口  集团
		StoreVo groupStoreVo= getPrcFactSmdOrg(groupId,reportDate,groupMonitorConfigDetailList);
		String dimensionCode=DimensionEnum.A.getKey();
		String dimensionName= DimensionEnum.A.getValue();
		//静态储备周期详情
		List<MonitorConfigDetailDto>agList=groupMonitorConfigDetailList.stream()
				.filter(x->x.getTargetCode().equals(TargetNameEnum.A.getKey())).collect(Collectors.toList());
		//动态储备周期监控详情
		List<MonitorConfigDetailDto>bgList=groupMonitorConfigDetailList.stream()
				.filter(x->x.getTargetCode().equals(TargetNameEnum.B.getKey())).collect(Collectors.toList());
		
		//静态储备周期(年)和动态储备周期(年) 都不为空 才往下执行
		if(StringUtils.isNotEmpty(groupStoreVo.getStaticResvCycle()) && StringUtils.isNotEmpty(groupStoreVo.getDynamicResvCycle())) {
			//集团预警条件
			String groupCondition = getEarlyWarningConditions(HrOrgTypeEunm.ORG_11.getKey(), groupId, DimensionEnum.A.getKey(), reportDate);
			
			//是否满足预警条件
			String agStatus=Constants.NONE;
			String bgStatus=Constants.NONE;
			if(StringUtils.isNotEmpty(groupStoreVo.getStaticResvCycle())) {
				agStatus=getStatus(agList, Double.parseDouble(groupStoreVo.getStaticResvCycle()));
			}
			if(StringUtils.isNotEmpty(groupStoreVo.getDynamicResvCycle())) {
				bgStatus=getStatus(bgList, Double.parseDouble(groupStoreVo.getDynamicResvCycle()));
			}
			
			if(!agStatus.equals(Constants.NONE) && !bgStatus.equals(Constants.NONE)) {
				if(agStatus.equals(Constants.WARNING) && bgStatus.equals(Constants.WARNING)) {
					//判断所有条件是否都满足 预警标准
					//集团总体土储不足，静态储备周期×，动态储备周期×，请知悉
					String targetNames=TargetNameEnum.A.getValue()+groupStoreVo.getStaticResvCycle()+","
							+TargetNameEnum.B.getValue()+groupStoreVo.getDynamicResvCycle()+","+Constants.PLEASE_KNOW;
					String content=Constants.GROUP_OVERALL+Constants.INSUFFICIENT_SOIL_STORAGE+","+targetNames;
					//提醒人员
					List<String> positionGroupIds = getWarningStaff(dimensionCode,TodoOrgTypeEnum.ONE.getValue(),LevelEnum.ZERO.getKey(),warningConfigList);
					List<IdmUser> userList = idmUserMapper.selectGroupPrincipal(positionGroupIds, groupId);
					
					insertMonitorWarningLog(reportDate,groupId,"","","","","",groupId,"旭辉集团",TodoOrgTypeEnum.ONE.getValue(),dimensionCode, dimensionName,groupCondition, content,userList,monitorWarningLogList);
//					sendWarning(groupId, "", "", "",TodoOrgTypeEnum.ONE.getKey(), dimensionCode,dimensionName,groupCondition,reportDate,content,userList);
					
				}
			}

			List<ProjectByStagesDto> regionList = orgList.stream().filter(x-> groupId.equals(x.getParentOrgid())).collect(Collectors.toList());
			
			for (ProjectByStagesDto p : regionList) {
				List<MonitorConfigDetailDto> regionMonitorConfigDetailList=getDetailByOrgId(p.getOrgdepid(),HrOrgTypeEunm.ORG_20.getKey()); 
				StoreVo regionStoreVo = getPrcFactSmdOrg(p.getOrgdepid(),reportDate,regionMonitorConfigDetailList);
				if(StringUtils.isNotEmpty(regionStoreVo.getStaticResvCycle()) && StringUtils.isNotEmpty(regionStoreVo.getDynamicResvCycle())) {
					//静态储备周期详情
					List<MonitorConfigDetailDto>arList=regionMonitorConfigDetailList.stream()
							.filter(x->x.getTargetCode().equals(TargetNameEnum.A.getKey())).collect(Collectors.toList());
					//动态储备周期监控详情
					List<MonitorConfigDetailDto>brList=regionMonitorConfigDetailList.stream()
							.filter(x->x.getTargetCode().equals(TargetNameEnum.B.getKey())).collect(Collectors.toList());
					//是否满足预警条件
					String arStatus=Constants.NONE;
					String brStatus=Constants.NONE;
					if(StringUtils.isNotEmpty(regionStoreVo.getStaticResvCycle())) {
						arStatus=getStatus(arList, Double.parseDouble(regionStoreVo.getStaticResvCycle()));
					}
					if(StringUtils.isNotEmpty(regionStoreVo.getDynamicResvCycle())) {
						 brStatus=getStatus(brList, Double.parseDouble(regionStoreVo.getDynamicResvCycle()));
					}
					
					if(!arStatus.equals(Constants.NONE) && !brStatus.equals(Constants.NONE)) {
						if(arStatus.equals(Constants.WARNING) && brStatus.equals(Constants.WARNING)) {
							//判断所有条件是否都满足 预警标准
							//区域预警条件
							String regionCondition=getEarlyWarningConditions(HrOrgTypeEunm.ORG_20.getKey(), p.getOrgdepid(), DimensionEnum.A.getKey(), reportDate);
							//××区域/事业部土储不足，静态储备周期×，动态储备周期×，请知悉
							String targetNames=TargetNameEnum.A.getValue()+regionStoreVo.getStaticResvCycle()+","
									+TargetNameEnum.B.getValue()+regionStoreVo.getDynamicResvCycle()+","+Constants.PLEASE_KNOW;
							String rContent=p.getOrgname()+Constants.INSUFFICIENT_SOIL_STORAGE+","+targetNames;
							
							//区域
							List<String> regionGroupIds = getWarningStaff(dimensionCode,TodoOrgTypeEnum.TWO.getValue(),LevelEnum.ZERO.getKey(),warningConfigList);
							//上一级
							List<String> parentGroupIds = getWarningStaff(dimensionCode,TodoOrgTypeEnum.TWO.getValue(),LevelEnum.ONE.getKey(),warningConfigList);
							
							String orgPath = String.join("-", groupId,p.getOrgdepid());
							//开始发送
							List<IdmUser> userList = idmUserMapper.selectRegionPrincipal(regionGroupIds,parentGroupIds,p.getOrgdepid(),groupId);
							
							insertMonitorWarningLog(reportDate,"",p.getOrgdepid(),"","",groupId,"旭辉集团",p.getOrgdepid(),p.getOrgname(),TodoOrgTypeEnum.TWO.getValue(),dimensionCode, dimensionName,regionCondition, rContent,userList,monitorWarningLogList);
							
//							sendWarning(groupId, p.getOrgdepid(), "", "",TodoOrgTypeEnum.TWO.getKey(), dimensionCode,dimensionName,regionCondition,reportDate,rContent,userList);
							
						}
					}
				}
			}
		}
	}
	
	private List<String> getWarningStaff(String dimensionCode, String orgType, String level, List<MonitorWarningConfig> warningConfigList) {
		List<String> positionGroupIds = new ArrayList<>();
		for(MonitorWarningConfig config : warningConfigList) {
			if(config.getDimensionCode().equals(dimensionCode) && config.getOrgType().equals(orgType) && config.getLevel().equals(level)) {
				positionGroupIds.add(config.getPositionGroupId());
			}
		}
		return positionGroupIds;
	}
	

	private void insertMonitorWarningLog(String reportDate,String groupId,String regionId,String cityId,String projectId,
			String parentId, String parentName,String orgId, String orgName,String orgType, String dimensionCode,
			String dimensionName, String condition ,String content,List<IdmUser> userList,
			List<MonitorWarningLog> monitorWarningLogList) {
			for(IdmUser user : userList) {
				if(user != null) {
					MonitorWarningLog monitorWarningLog = new MonitorWarningLog();
					monitorWarningLog.setId(UUIDUtils.create());
					monitorWarningLog.setYearMonth(reportDate);
					monitorWarningLog.setGroupId(groupId);
					monitorWarningLog.setRegionId(regionId);
					monitorWarningLog.setCityId(cityId);
					monitorWarningLog.setProjectId(projectId);
					monitorWarningLog.setParentId(parentId);
					monitorWarningLog.setParentName(parentName);
					monitorWarningLog.setOrgId(orgId);
					monitorWarningLog.setOrgName(orgName);
					monitorWarningLog.setOrgType(orgType);
					monitorWarningLog.setDimensionCode(dimensionCode);
					monitorWarningLog.setDimensionName(dimensionName);
					monitorWarningLog.setCondition(condition);
					monitorWarningLog.setContent(content);
					monitorWarningLog.setRemindAccount(user.getAlias());
					monitorWarningLog.setRemindName(user.getUsercn());
					monitorWarningLog.setPositionNum(user.getPositionCode());
					monitorWarningLog.setPositionName(user.getPosition());
					monitorWarningLog.setCreateTime(LocalDateTime.now());
					monitorWarningLog.setUpdateTime(LocalDateTime.now());
					monitorWarningLogList.add(monitorWarningLog);
				}
			}
	}
	
	
	/**
	 * 发送产预警信息
	 */
	public void sendProduce(String groupId,String reportDate,List<ProjectByStagesDto> orgList,
			List<MonitorConfigDetailDto> groupMonitorConfigDetailList,List<MonitorWarningConfig> warningConfigList,List<MonitorWarningLog> monitorWarningLogList) {
		// 集团
		String dimensionCode = DimensionEnum.B.getKey();
		//提醒人员
		List<String> gPositionGroupIds = getWarningStaff(dimensionCode,TodoOrgTypeEnum.ONE.getValue(),LevelEnum.ZERO.getKey(),warningConfigList);
		List<IdmUser> userList = idmUserMapper.selectGroupPrincipal(gPositionGroupIds, groupId);
		
		verifyProduceWhetherTosend(groupId, "", "", "", TodoOrgTypeEnum.ONE.getKey(), reportDate,
				HrOrgTypeEunm.ORG_11.getKey(), groupId, Constants.GROUP_OVERALL,userList,monitorWarningLogList);

		List<ProjectByStagesDto> regionList = orgList.stream().filter(x-> groupId.equals(x.getParentOrgid())).collect(Collectors.toList());
		// 汇总接口 区域
		for (ProjectByStagesDto r : regionList) {
			// 提醒人员
			List<String> rPositionGroupIds = getWarningStaff(dimensionCode,TodoOrgTypeEnum.TWO.getValue(),LevelEnum.ZERO.getKey(),warningConfigList);
			// 上一级提醒人员
			List<String> rParentGroupIds = getWarningStaff(dimensionCode,TodoOrgTypeEnum.TWO.getValue(),LevelEnum.ONE.getKey(),warningConfigList);
			
			String orgPath = String.join("-", groupId,r.getOrgdepid());
			List<IdmUser> rUserList = idmUserMapper.selectRegionPrincipal(rPositionGroupIds,rParentGroupIds,r.getOrgdepid(),groupId);
			
			verifyProduceWhetherTosend(groupId, r.getOrgdepid(), "", "", TodoOrgTypeEnum.TWO.getKey(),
					reportDate, HrOrgTypeEunm.ORG_20.getKey(), r.getOrgdepid(), r.getOrgname(),rUserList,monitorWarningLogList);
			
			// 城市
			List<ProjectByStagesDto> cityList = orgList.stream().filter(x-> r.getOrgdepid().equals(x.getParentOrgid())).collect(Collectors.toList());
			for (ProjectByStagesDto c : cityList) {
				// 提醒人员
				List<String> cityGroupIds = getWarningStaff(dimensionCode,TodoOrgTypeEnum.THREE.getValue(),LevelEnum.ZERO.getKey(),warningConfigList);
				// 上一级提醒人员
				List<String> cParentGroupIds = getWarningStaff(dimensionCode,TodoOrgTypeEnum.THREE.getValue(),LevelEnum.ONE.getKey(),warningConfigList);
				
				String cOrgPath = String.join("-", groupId,r.getOrgdepid(),c.getOrgdepid());
				List<IdmUser> cUserList = idmUserMapper.selectRegionPrincipal(cityGroupIds,cParentGroupIds,c.getOrgdepid(),r.getOrgdepid());
				
				verifyProduceWhetherTosend(groupId, r.getOrgdepid(), c.getOrgdepid(), "",
						TodoOrgTypeEnum.THREE.getKey(), reportDate, HrOrgTypeEunm.ORG_21.getKey(), c.getOrgdepid(),
						c.getOrgname(),cUserList,monitorWarningLogList);
				
				// 项目
				List<ProjectByStagesDto> projectList = orgList.stream().filter(x-> c.getOrgdepid().equals(x.getParentOrgid())).collect(Collectors.toList());
				for (ProjectByStagesDto p : projectList) {
					// 提醒人员
					List<String> projectGroupIds = getWarningStaff(dimensionCode,TodoOrgTypeEnum.FOUR.getValue(),LevelEnum.ZERO.getKey(),warningConfigList);
					// 上一级提醒人员
					List<String> pParentGroupIds = getWarningStaff(dimensionCode,TodoOrgTypeEnum.FOUR.getValue(),LevelEnum.ONE.getKey(),warningConfigList);
					
					String pOrgPath = String.join("-", groupId,r.getOrgdepid(),c.getOrgdepid(),p.getOrgdepid());
					List<IdmUser> pUserList = idmUserMapper.selectRegionPrincipal(projectGroupIds,pParentGroupIds,p.getOrgdepid(),c.getOrgdepid());
					
					verifyProduceWhetherTosend(groupId, r.getOrgdepid(), c.getOrgdepid(), p.getOrgdepid(),
							TodoOrgTypeEnum.FOUR.getKey(), reportDate, HrOrgTypeEunm.ORG_31.getKey(), p.getOrgdepid(),
							p.getOrgname(),pUserList,monitorWarningLogList);
				}
				
			}
			
		}
	}

	/**
	 * 发送销预警信息
	 */
	public void sendSale(String groupId,String reportDate,List<ProjectByStagesDto>orgList,List<MonitorConfigDetailDto> groupMonitorConfigDetailList,List<MonitorWarningConfig> warningConfigList,List<MonitorWarningLog> monitorWarningLogList) {
		String dimensionCode = DimensionEnum.D.getKey();
		// 提醒人员 
		List<String> gPositionGroupIds = getWarningStaff(dimensionCode,TodoOrgTypeEnum.ONE.getValue(),LevelEnum.ZERO.getKey(),warningConfigList);
		List<IdmUser> userList = idmUserMapper.selectGroupPrincipal(gPositionGroupIds, groupId);
		verifySaleWhetherTosend(groupId, "", "", "", TodoOrgTypeEnum.ONE.getKey(), reportDate, HrOrgTypeEunm.ORG_11.getKey(), groupId, Constants.GROUP_OVERALL,userList,monitorWarningLogList);

		// 区域
		List<ProjectByStagesDto> regionList = orgList.stream().filter(x-> groupId.equals(x.getParentOrgid())).collect(Collectors.toList());
		for (ProjectByStagesDto r : regionList) {
			// 提醒人员
			List<String> regionGroupIds = getWarningStaff(dimensionCode,TodoOrgTypeEnum.TWO.getValue(),LevelEnum.ZERO.getKey(),warningConfigList);
			//上一级 提醒人员
			List<String> rParentGroupIds = getWarningStaff(dimensionCode,TodoOrgTypeEnum.TWO.getValue(),LevelEnum.ONE.getKey(),warningConfigList);
			
			String orgPath = String.join("-", groupId,r.getOrgdepid());
			List<IdmUser> rUserList = idmUserMapper.selectRegionPrincipal(regionGroupIds,rParentGroupIds,r.getOrgdepid(),groupId);
			
			verifySaleWhetherTosend(groupId, r.getOrgdepid(), "", "", TodoOrgTypeEnum.TWO.getKey(),
					reportDate, HrOrgTypeEunm.ORG_20.getKey(), r.getOrgdepid(), r.getOrgname(),rUserList,monitorWarningLogList);
			
			// 城市
			List<ProjectByStagesDto> cityList = orgList.stream().filter(x-> r.getOrgdepid().equals(x.getParentOrgid())).collect(Collectors.toList());
			for (ProjectByStagesDto c : cityList) {
				// 提醒人员
				List<String> cityGroupIds = getWarningStaff(dimensionCode,TodoOrgTypeEnum.THREE.getValue(),LevelEnum.ZERO.getKey(),warningConfigList);
				//上一级 提醒人员
				List<String> cParentGroupIds = getWarningStaff(dimensionCode,TodoOrgTypeEnum.THREE.getValue(),LevelEnum.ONE.getKey(),warningConfigList);
				
				String cOrgPath = String.join("-", groupId,r.getOrgdepid(),c.getOrgdepid());
				List<IdmUser> cUserList = idmUserMapper.selectRegionPrincipal(cityGroupIds,cParentGroupIds,c.getOrgdepid(),r.getOrgdepid());
				
				verifySaleWhetherTosend(groupId, r.getOrgdepid(), c.getOrgdepid(), "",
						TodoOrgTypeEnum.THREE.getKey(), reportDate, HrOrgTypeEunm.ORG_21.getKey(), c.getOrgdepid(),
						c.getOrgname(),cUserList,monitorWarningLogList);
				
				// 项目
				List<ProjectByStagesDto> projectList = orgList.stream().filter(x-> c.getOrgdepid().equals(x.getParentOrgid())).collect(Collectors.toList());
				for (ProjectByStagesDto p : projectList) {
					// 提醒人员
					List<String> projectGroupIds = getWarningStaff(dimensionCode,TodoOrgTypeEnum.FOUR.getValue(),LevelEnum.ZERO.getKey(),warningConfigList);
					//上一级 提醒人员
					List<String> pParentGroupIds = getWarningStaff(dimensionCode,TodoOrgTypeEnum.FOUR.getValue(),LevelEnum.ONE.getKey(),warningConfigList);
					
					String pOrgPath = String.join("-", groupId,r.getOrgdepid(),c.getOrgdepid(),p.getOrgdepid());
					List<IdmUser> pUserList = idmUserMapper.selectRegionPrincipal(projectGroupIds,pParentGroupIds,p.getOrgdepid(),c.getOrgdepid());
					
					verifySaleWhetherTosend(groupId, r.getOrgdepid(), c.getOrgdepid(), p.getOrgdepid(),
							TodoOrgTypeEnum.FOUR.getKey(), reportDate, HrOrgTypeEunm.ORG_31.getKey(), p.getOrgdepid(),
							p.getOrgname(),pUserList,monitorWarningLogList);
				}
				
			}
		}
	}
	
	
	
	/**
	 * 发送存预警信息
	 */
	public void sendStock(String groupId,String reportDate,List<ProjectByStagesDto> orgList,List<MonitorConfigDetailDto> groupMonitorConfigDetailList,List<MonitorWarningConfig> warningConfigList,List<MonitorWarningLog> monitorWarningLogList) {
		String dimensionCode = DimensionEnum.E.getKey();
		// 集团
		List<String> gPositionGroupIds = getWarningStaff(dimensionCode,TodoOrgTypeEnum.ONE.getValue(),LevelEnum.ZERO.getKey(),warningConfigList);
		List<IdmUser> userList = idmUserMapper.selectGroupPrincipal(gPositionGroupIds, groupId);
		verifyStockWhetherTosend(groupId, "", "", "", TodoOrgTypeEnum.ONE.getKey(), reportDate,
				HrOrgTypeEunm.ORG_11.getKey(), groupId, Constants.GROUP_OVERALL,userList,monitorWarningLogList);
		
		// 区域
		List<ProjectByStagesDto> regionList = orgList.stream().filter(x-> groupId.equals(x.getParentOrgid())).collect(Collectors.toList());
		for (ProjectByStagesDto r : regionList) {
			// 提醒人员
			List<String> currentGroupIds = getWarningStaff(dimensionCode,TodoOrgTypeEnum.TWO.getValue(),LevelEnum.ZERO.getKey(),warningConfigList);
			List<String> rParentGroupIds = getWarningStaff(dimensionCode,TodoOrgTypeEnum.TWO.getValue(),LevelEnum.ONE.getKey(),warningConfigList);
			
			String orgPath = String.join("-", groupId,r.getOrgdepid());
			List<IdmUser> rUserList = idmUserMapper.selectRegionPrincipal(currentGroupIds,rParentGroupIds,r.getOrgdepid(),groupId);
			
			verifyStockWhetherTosend(groupId, r.getOrgdepid(), "", "", TodoOrgTypeEnum.TWO.getKey(),
					reportDate, HrOrgTypeEunm.ORG_20.getKey(), r.getOrgdepid(), r.getOrgname(),rUserList,monitorWarningLogList);
			
			// 城市
			List<ProjectByStagesDto> cityList = orgList.stream().filter(x-> r.getOrgdepid().equals(x.getParentOrgid())).collect(Collectors.toList());
			for (ProjectByStagesDto c : cityList) {
				// 提醒人员
				List<String> cityGroupIds = getWarningStaff(dimensionCode,TodoOrgTypeEnum.THREE.getValue(),LevelEnum.ZERO.getKey(),warningConfigList);
				//上一级提醒人员
				List<String> cParentGroupIds = getWarningStaff(dimensionCode,TodoOrgTypeEnum.THREE.getValue(),LevelEnum.ONE.getKey(),warningConfigList);
				
				String cOrgPath = String.join("-", groupId,r.getOrgdepid(),c.getOrgdepid());
				List<IdmUser> cUserList = idmUserMapper.selectRegionPrincipal(cityGroupIds,cParentGroupIds,c.getOrgdepid(),r.getOrgdepid());
				
				verifyStockWhetherTosend(groupId, r.getOrgdepid(), c.getOrgdepid(), "",
						TodoOrgTypeEnum.THREE.getKey(), reportDate, HrOrgTypeEunm.ORG_21.getKey(), c.getOrgdepid(),
						c.getOrgname(),cUserList,monitorWarningLogList);
				
				// 项目
				List<ProjectByStagesDto> projectList = orgList.stream().filter(x-> c.getOrgdepid().equals(x.getParentOrgid())).collect(Collectors.toList());
				for (ProjectByStagesDto p : projectList) {
					// 提醒人员
					List<String> projectGroupIds = getWarningStaff(dimensionCode,TodoOrgTypeEnum.FOUR.getValue(),LevelEnum.ZERO.getKey(),warningConfigList);
					//上一级提醒人员
					List<String> pParentGroupIds = getWarningStaff(dimensionCode,TodoOrgTypeEnum.FOUR.getValue(),LevelEnum.ONE.getKey(),warningConfigList);
					
					String pOrgPath = String.join("-", groupId,r.getOrgdepid(),c.getOrgdepid(),p.getOrgdepid());
					List<IdmUser> pUserList = idmUserMapper.selectRegionPrincipal(projectGroupIds,pParentGroupIds,p.getOrgdepid(),c.getOrgdepid());
					
					verifyStockWhetherTosend(groupId, r.getOrgdepid(), c.getOrgdepid(), p.getOrgdepid(),
							TodoOrgTypeEnum.FOUR.getKey(), reportDate, HrOrgTypeEunm.ORG_31.getKey(), p.getOrgdepid(),
							p.getOrgname(),pUserList,monitorWarningLogList);
				}	
			}
		}
	}
	
	
	/**
	 * 发送结预警信息
	 */
	public void sendStatement(String groupId,String reportDate,List<ProjectByStagesDto>orgList,List<MonitorConfigDetailDto> groupMonitorConfigDetailList,List<MonitorWarningConfig> warningConfigList,List<MonitorWarningLog> monitorWarningLogList) {
		String dimensionCode = DimensionEnum.F.getKey();
		// 集团
		// 提醒人员
		List<String> gPositionGroupIds = getWarningStaff(dimensionCode,TodoOrgTypeEnum.ONE.getValue(),LevelEnum.ZERO.getKey(),warningConfigList);
		List<IdmUser> userList = idmUserMapper.selectGroupPrincipal(gPositionGroupIds, groupId);
		verifyStatementWhetherTosend(groupId, "", "", "", TodoOrgTypeEnum.ONE.getKey(), reportDate,
				HrOrgTypeEunm.ORG_11.getKey(), groupId, Constants.GROUP_OVERALL,userList,monitorWarningLogList);

		// 区域
		List<ProjectByStagesDto> regionList = orgList.stream().filter(x-> groupId.equals(x.getParentOrgid())).collect(Collectors.toList());
		for (ProjectByStagesDto r : regionList) {
			// 提醒人员
			List<String> regionGroupIds = getWarningStaff(dimensionCode,TodoOrgTypeEnum.TWO.getValue(),LevelEnum.ZERO.getKey(),warningConfigList);
			//上一级提醒人员
			List<String> rParentGroupIds = getWarningStaff(dimensionCode,TodoOrgTypeEnum.TWO.getValue(),LevelEnum.ONE.getKey(),warningConfigList);
			
			String orgPath = String.join("-", groupId,r.getOrgdepid());
			List<IdmUser> rUserList = idmUserMapper.selectRegionPrincipal(regionGroupIds,rParentGroupIds,r.getOrgdepid(),groupId);
			
			verifyStatementWhetherTosend(groupId, r.getOrgdepid(), "", "", TodoOrgTypeEnum.TWO.getKey(),
					reportDate, HrOrgTypeEunm.ORG_20.getKey(), r.getOrgdepid(), r.getOrgname(),rUserList,monitorWarningLogList);
			
			// 城市
			List<ProjectByStagesDto> cityList = orgList.stream().filter(x-> r.getOrgdepid().equals(x.getParentOrgid())).collect(Collectors.toList());
			for (ProjectByStagesDto c : cityList) {
				// 提醒人员 					
				List<String> cityGroupIds = getWarningStaff(dimensionCode,TodoOrgTypeEnum.THREE.getValue(),LevelEnum.ZERO.getKey(),warningConfigList);
				//上一级提醒人员
				List<String> cParentGroupIds = getWarningStaff(dimensionCode,TodoOrgTypeEnum.THREE.getValue(),LevelEnum.ONE.getKey(),warningConfigList);
				
				String cOrgPath = String.join("-", groupId,r.getOrgdepid(),c.getOrgdepid());
				List<IdmUser> cUserList = idmUserMapper.selectRegionPrincipal(cityGroupIds,cParentGroupIds,c.getOrgdepid(),r.getOrgdepid());
				
				verifyStatementWhetherTosend(groupId, r.getOrgdepid(), c.getOrgdepid(), "",
						TodoOrgTypeEnum.THREE.getKey(), reportDate, HrOrgTypeEunm.ORG_21.getKey(), c.getOrgdepid(),c.getOrgname(),cUserList,monitorWarningLogList);
			
				// 项目
				List<ProjectByStagesDto> projectList = orgList.stream().filter(x-> c.getOrgdepid().equals(x.getParentOrgid())).collect(Collectors.toList());
				for (ProjectByStagesDto p : projectList) {
					// 提醒人员	
					List<String> projectGroupIds = getWarningStaff(dimensionCode,TodoOrgTypeEnum.FOUR.getValue(),LevelEnum.ZERO.getKey(),warningConfigList);
					//上一级提醒人员
					List<String> pParentGroupIds = getWarningStaff(dimensionCode,TodoOrgTypeEnum.FOUR.getValue(),LevelEnum.ONE.getKey(),warningConfigList);
					
					String pOrgPath = String.join("-", groupId,r.getOrgdepid(),c.getOrgdepid(),p.getOrgdepid());
					List<IdmUser> pUserList = idmUserMapper.selectRegionPrincipal(projectGroupIds,pParentGroupIds,p.getOrgdepid(),c.getOrgdepid());
					
					verifyStatementWhetherTosend(groupId, r.getOrgdepid(), c.getOrgdepid(), p.getOrgdepid(),
							TodoOrgTypeEnum.FOUR.getKey(), reportDate, HrOrgTypeEunm.ORG_31.getKey(), p.getOrgdepid(),p.getOrgname(),pUserList,monitorWarningLogList);
				}
			}
		}
	}
	
	/**
	 * 根据组织类型和维度类型返回预警条件
	 * @return
	 */
	public String getEarlyWarningConditions(String hrOrgTypeId,String orgId,String dimensionCode,String reportDate) {
		List<MonitorConfigDetailDto> monitorConfigDetailDtoList=getDetailByOrgId(orgId,hrOrgTypeId); 
		//静态储备周期
		String staticResvCycle="";
		//动态储备周期
		String dynamicResvCycle="";
		//首开项目开销比
		String firstOpenOvhdRateList="";
		//续销项目在途比
		String renewalInTransitRateList="";
		//库存去化率
		String stockRemovalRateList="";
		//长期库存去化率
		String stockRemovalRatelongtime="";
		//存销比
		String storeSaleRate="";
		//长期库存
		String storeLongTime="";
		//长期库存存销比
		String storeSaleRatelongtime="";
		//结转去化率  1-6月取上半年 7-12取下半年
		String statementRate="";
		//截取月份
		String month=reportDate.substring(4,6);
		
		if(CollectionUtils.isNotEmpty(monitorConfigDetailDtoList)) {
			for (MonitorConfigDetailDto md : monitorConfigDetailDtoList) {
				//监控设置明细类型(1健康标准2提醒标准3预警标准)
				if(md.getMonitorType().equals(Constants.THREE+"")) {
					//只要预警标准
					//静态储备周期
					if(md.getTargetCode().equals(TargetNameEnum.A.getKey())) {
						staticResvCycle=OperatorUtils.splicingOperator(md,TargetNameEnum.A.getValue());
					}
					//动态储备周期
					if(md.getTargetCode().equals(TargetNameEnum.B.getKey())) {
						dynamicResvCycle=OperatorUtils.splicingOperator(md,TargetNameEnum.B.getValue());
					}
					//首开项目开销比
					if(md.getTargetCode().equals(TargetNameEnum.C.getKey())) {
						firstOpenOvhdRateList=OperatorUtils.splicingOperator(md,TargetNameEnum.C.getValue());
					}
					//续销项目在途比
					if(md.getTargetCode().equals(TargetNameEnum.D.getKey())) {
						renewalInTransitRateList=OperatorUtils.splicingOperator(md,TargetNameEnum.D.getValue());
					}
					//库存去化率
					if(md.getTargetCode().equals(TargetNameEnum.I.getKey())) {
						stockRemovalRateList=OperatorUtils.splicingOperator(md,TargetNameEnum.I.getValue());
					}
					//长期库存去化率
					if(md.getTargetCode().equals(TargetNameEnum.J.getKey())) {
						stockRemovalRatelongtime=OperatorUtils.splicingOperator(md,TargetNameEnum.J.getValue());
					}
					//存销比
					if(md.getTargetCode().equals(TargetNameEnum.L.getKey())) {
						storeSaleRate=OperatorUtils.splicingOperator(md,TargetNameEnum.L.getValue());
					}
					//长期库存占比
					if(md.getTargetCode().equals(TargetNameEnum.M.getKey())) {
						storeLongTime=OperatorUtils.splicingOperator(md,TargetNameEnum.M.getValue());
					}
					//长期库存存销比
					if(md.getTargetCode().equals(TargetNameEnum.O.getKey())) {
						storeSaleRatelongtime=OperatorUtils.splicingOperator(md,TargetNameEnum.O.getValue());
					}
					//结转去化率  1-6月取上半年 
					if(md.getTargetCode().equals(TargetNameEnum.Q.getKey())) {
						if(Integer.parseInt(month)<=Constants.SIX) {
							statementRate=OperatorUtils.splicingOperator(md,TargetNameEnum.Q.getValue());
						}
					}
					//结转去化率   7-12取下半年
					if(md.getTargetCode().equals(TargetNameEnum.R.getKey())) {
						if(Integer.parseInt(month)>=Constants.SEVEN) {
							statementRate=OperatorUtils.splicingOperator(md,TargetNameEnum.R.getValue());
						}
					}
				}
			}
		}
		String msg="";
		if (dimensionCode.equals(DimensionEnum.A.getKey())) {
			// 储
			msg=staticResvCycle+ConditionTypeEnum.TWO.getValue()+dynamicResvCycle;
		}
		if (dimensionCode.equals(DimensionEnum.B.getKey())) {
			// 产
			msg=firstOpenOvhdRateList+ConditionTypeEnum.TWO.getValue()+renewalInTransitRateList;
			
			if(hrOrgTypeId.equals(HrOrgTypeEunm.ORG_31.getKey()) || hrOrgTypeId.equals(HrOrgTypeEunm.ORG_23.getKey())) {
				//产的项目 取或
				msg=firstOpenOvhdRateList+ConditionTypeEnum.ONE.getValue()+renewalInTransitRateList;
			}
		}
		if (dimensionCode.equals(DimensionEnum.D.getKey())) {
			// 销
			msg=stockRemovalRateList+ConditionTypeEnum.TWO.getValue()+stockRemovalRatelongtime;
		}
		if (dimensionCode.equals(DimensionEnum.E.getKey())) {
			// 存
		    msg=storeSaleRate+ConditionTypeEnum.TWO.getValue()
		    		+storeLongTime+ConditionTypeEnum.TWO.getValue()
		    		+storeSaleRatelongtime;
		}
		if (dimensionCode.equals(DimensionEnum.F.getKey())) {
			// 结
			msg=statementRate;
		}
		return msg;
	}
	
	/**
	 * 业态存销比
	 */
	@Override
	public List<StoreSaleRateVo> getStoreSaleRate(String orgId, String reportDate) {
		List<StoreSaleRateVo>list=getDataStoreSaleRateList(orgId, reportDate);
		return list;
	}
	
	/**
	 * 调用数据中心 业态存销比
	 * @param orgId
	 * @param reportDate
	 * @return
	 */
	public List<StoreSaleRateVo>getDataStoreSaleRateList(String orgId, String reportDate){
		List<StoreSaleRateVo> list=new ArrayList<>();
		//日志路径
		String logUrl="MonitoringConsoleServiceImpl/getDataStoreSaleRateList";
		//标题
		String title="获取存-业态存销比接口";
		
		BasicAuthClient bac = new BasicAuthClient();
		String api =storeSaleRate_url+orgId+","+reportDate;
		//拼接地址
		String url = data_middle_ground_url+api;
		String result = bac.getData(url, data_api_key, data_api_value);
		log.info("###存-业态存销比接口 地址： "+url);
		log.info("###存-业态存销比接口 返回数据："+result);
		JSONObject jsonObject=JSONObject.parseObject(result);
		if(jsonObject!=null) {
			int retCode=jsonObject.getInteger("retCode");
			//0
			if(retCode==Constants.ZERO) {
				//获取成功
				JSONArray retData=jsonObject.getJSONArray("retData");	
				for (int i = 0; i < retData.size(); i++) {
					JSONObject retDataObj=retData.getJSONObject(i);
					String code=retDataObj.getString("code");
					String name=retDataObj.getString("name");
					Double rate=retDataObj.getDouble("rate");
					StoreSaleRateVo vo=new StoreSaleRateVo();
					vo.setCode(code);
					vo.setName(name);
					vo.setRate(rate.toString());
					list.add(vo);
				}
				return list;
			}else {
				//获取失败
				log.info("获取存-业态存销比接口失败");
				saveLog("获取存-业态存销比接口失败",logUrl,title,Constants.MONITORING_CONSOLE);
			}
		}else {
			log.info("获取存-业态存销比接口失败");
			saveLog("获取存-业态存销比接口失败",logUrl,title,Constants.MONITORING_CONSOLE);
		}
		return list;
	}
	
	/**
	 * 优化发送集团到项目待办
	 * @param prevOrgId 上一级部门id
	 * @param groupHeadId 集团总部id
	 */
	public void sendStart(String groupId,String regionId,String cityId,
			String projectId,List<String>positionGroupIds,String todoOrgType
			,String dimensionCode,String dimensionName,String condition,String reportDate,String content,
			String prevOrgId,String groupHeadId) {
		List<IdmUser> userList=new ArrayList<>();
		String orgId="";
		if(todoOrgType.equals(TodoOrgTypeEnum.ONE.getKey())) {
			//集团
			userList=getPositionGroupsUserListV2(positionGroupIds, groupId,prevOrgId,groupHeadId);
			orgId=groupId;
		}
		if(todoOrgType.equals(TodoOrgTypeEnum.TWO.getKey())) {
			//区域加上集团总部id
			userList=getPositionGroupsUserListV2(positionGroupIds, regionId,prevOrgId,groupHeadId);
			orgId=regionId;
		}	
		if(todoOrgType.equals(TodoOrgTypeEnum.THREE.getKey())) {
			//城市公司
			userList=getPositionGroupsUserListV2(positionGroupIds,cityId,prevOrgId,groupHeadId);
			orgId=cityId;
		}
		if(todoOrgType.equals(TodoOrgTypeEnum.FOUR.getKey())) {
			//项目
			userList=getPositionGroupsUserListV2(positionGroupIds, projectId,prevOrgId,groupHeadId);
			orgId=projectId;
		}
		PortalTodoBo doorTodoBo=new PortalTodoBo();
		doorTodoBo.setTitle(content);
		//任务类型，待办列表中显示在主题前面的中括号中，表示提醒审批人待审批的是什么。如“转交”，“驳回”，“合同审批”等，最多用四个字来总结
		//预警提醒
		doorTodoBo.setTodoType(TodoTypeCodeEnum.EARLY_WARNING.getValue());
		//任务类型code
		doorTodoBo.setTodoTypeCode(TodoTypeCodeEnum.EARLY_WARNING.getKey());
		//待办组织类型 
		doorTodoBo.setOrgType(todoOrgType);
        //集团id
        doorTodoBo.setGroupId(groupId);
        //区域或事业部id
        doorTodoBo.setRegionId(regionId);
        //城市公司id
        doorTodoBo.setCityId(cityId);
        //项目id
        doorTodoBo.setProjectId(projectId);
        //待办说明
        doorTodoBo.setContent(content);

		//添加监控预警记录表
		String monitorWarningId=insertMonitorWarning(todoOrgType,
				orgId, dimensionCode, dimensionName, condition, reportDate);
		//提醒人员
		String reminderStaff="";
		if(CollectionUtils.isNotEmpty(userList)) {
			for (IdmUser idmUser : userList) {
				reminderStaff=idmUser.getAlias()+";"+reminderStaff;
			}
		}
		//添加监控预警指标表（记录基于维度预警的指标明细）
		String warningPortalId=insertMonitorWarningQuota(dimensionCode, dimensionName,
				reminderStaff, content, monitorWarningId);
		
		if(CollectionUtils.isNotEmpty(userList)) {
			//一个一个用户发送门户待办
			for (IdmUser idmUser : userList) {
				//门户待办id
		        String instanceId=commonService.sendMessagePortalTodoByUser(Constants.SYS, doorTodoBo,idmUser);
		        //添加监控预警门户提醒关系表
		        insertMonitorWarningPortal(warningPortalId, instanceId);
			}
		}
	}
	
	
	/**
	 * 优化发送集团到项目待办
	 */
	public void sendWarning(String groupId,String regionId,String cityId,String projectId,String todoOrgType,
			String dimensionCode,String dimensionName,String condition,String reportDate,String content,List<IdmUser> userList) {
		String orgId="";
		if(todoOrgType.equals(TodoOrgTypeEnum.ONE.getKey())) {
			//集团
			orgId=groupId;
		}
		if(todoOrgType.equals(TodoOrgTypeEnum.TWO.getKey())) {
			//区域加上集团总部id
			orgId=regionId;
		}	
		if(todoOrgType.equals(TodoOrgTypeEnum.THREE.getKey())) {
			//城市公司
			orgId=cityId;
		}
		if(todoOrgType.equals(TodoOrgTypeEnum.FOUR.getKey())) {
			//项目
			orgId=projectId;
		}
		PortalTodoBo doorTodoBo=new PortalTodoBo();
		doorTodoBo.setTitle(content);
		//任务类型，待办列表中显示在主题前面的中括号中，表示提醒审批人待审批的是什么。如“转交”，“驳回”，“合同审批”等，最多用四个字来总结
		//预警提醒
		doorTodoBo.setTodoType(TodoTypeCodeEnum.EARLY_WARNING.getValue());
		//任务类型code
		doorTodoBo.setTodoTypeCode(TodoTypeCodeEnum.EARLY_WARNING.getKey());
		//待办组织类型 
		doorTodoBo.setOrgType(todoOrgType);
        //集团id
        doorTodoBo.setGroupId(groupId);
        //区域或事业部id
        doorTodoBo.setRegionId(regionId);
        //城市公司id
        doorTodoBo.setCityId(cityId);
        //项目id
        doorTodoBo.setProjectId(projectId);
        //待办说明
        doorTodoBo.setContent(content);

		//添加监控预警记录表
		String monitorWarningId=insertMonitorWarning(todoOrgType,
				orgId, dimensionCode, dimensionName, condition, reportDate);
		//提醒人员
		String reminderStaff="";
		if(CollectionUtils.isNotEmpty(userList)) {
			for (IdmUser idmUser : userList) {
				reminderStaff=idmUser.getAlias()+";"+reminderStaff;
			}
		}
		//添加监控预警指标表（记录基于维度预警的指标明细）
		String warningPortalId=insertMonitorWarningQuota(dimensionCode, dimensionName,
				reminderStaff, content, monitorWarningId);
		
		if(CollectionUtils.isNotEmpty(userList)) {
			//一个一个用户发送门户待办
			for (IdmUser idmUser : userList) {
				//门户待办id
		        String instanceId=commonService.sendMessagePortalTodoByUser(Constants.SYS, doorTodoBo,idmUser);
		        //添加监控预警门户提醒关系表
		        insertMonitorWarningPortal(warningPortalId, instanceId);
			}
		}
	}
	
	
	
	
	
	/**
	 * 添加监控预警记录表
	 * @param todoOrgType
	 * @param orgId
	 * @param dimensionCode
	 * @param dimensionName
	 * @return
	 */
	public String insertMonitorWarning(String todoOrgType,String orgId,String dimensionCode,String dimensionName,
			String condition,String years) {
		 //监控预警记录表（基于维度交叉预警的记录）
        MonitorWarning monitorWarning=new MonitorWarning();
        String monitorWarningId=UUIDUtils.create();
        monitorWarning.setId(monitorWarningId);
        monitorWarning.setOrgtype(todoOrgType);
        monitorWarning.setOrgid(orgId);
		//纬度类型
		monitorWarning.setDimensionCode(dimensionCode);
		//交叉预警条件内容=预警条件
		monitorWarning.setContent(condition);
		//预警提醒年月
		monitorWarning.setYears(years);
		//维度名称
		monitorWarning.setDimensionName(dimensionName);
		monitorWarning.setCreateTime(LocalDateTime.now());
        monitorWarningMapper.insert(monitorWarning);
        return monitorWarningId;
	}
	
	/**
	 * 添加监控预警指标表（记录基于维度预警的指标明细）
	 * @return
	 */
	public String insertMonitorWarningQuota(String dimensionCode,String dimensionName,String reminderStaff,
			String reminderContent,String warningId) {
		MonitorWarningQuota monitorWarningQuota=new MonitorWarningQuota();
		String quotaId=UUIDUtils.create();
		monitorWarningQuota.setId(quotaId);
	    //维度编码
	    monitorWarningQuota.setDimensionCode(dimensionCode);
	    //维度名称
	    monitorWarningQuota.setDimensionName(dimensionName);
	    //提醒人员
	    monitorWarningQuota.setReminderStaff(reminderStaff);
	    //提醒内容
	    monitorWarningQuota.setReminderContent(reminderContent);
	    //预警记录id
	    monitorWarningQuota.setWarningId(warningId);
	    monitorWarningQuota.setCreateTime(LocalDateTime.now());
	    monitorWarningQuotaMapper.insert(monitorWarningQuota);
		return quotaId;		
	}
	
	/**
	 * 添加监控预警门户提醒关系表（关联 t_portal_todo，记录基于维度预警发出的门户待办提醒）
	 * @return
	 */
	public String insertMonitorWarningPortal(String warningPortalId,String instanceId) {
		MonitorWarningPortal monitorWarningPortal=new MonitorWarningPortal();
		String id=UUIDUtils.create();
		monitorWarningPortal.setId(id);
	    //预警指标明细id
		monitorWarningPortal.setWarningPortalId(warningPortalId);
	    //门户待办id
	    monitorWarningPortal.setInstanceId(instanceId);
	    monitorWarningPortal.setCreateTime(LocalDateTime.now());
	    monitorWarningPortalMapper.insert(monitorWarningPortal);
	    return id;
	}
	
	
	/**
	 * 获取多个岗位组的用户信息
	 * @param positionGroupIds
	 * @param orgId
	 * @return
	 */
	public List<IdmUser> getPositionGroupsUserList(List<String>positionGroupIds,String orgId) {
		HashSet<IdmUser>userList=new HashSet<>();
		for (String string : positionGroupIds) {
			//集团PMO办公室负责人
			List<IdmUser> list = idmUserService.getPositionGroupUserList(string, orgId);
			userList.addAll(list);
		}
		List<IdmUser>newUserList=new ArrayList<>();
		if(CollectionUtils.isNotEmpty(userList)) {
			for (IdmUser idmUser : userList) {
				newUserList.add(idmUser);
			}
		}
		return newUserList;
	}
	
	/**
	 * 销-验证是否发送门户待办
	 */
	public void verifySaleWhetherTosend(String groupId,String regionId,String cityId,String projectId,
			String todoOrgType,String reportDate,String hrOrgType,String orgId,String orgName,List<IdmUser> userList,List<MonitorWarningLog> monitorWarningLogList) {
		String dimensionCode = DimensionEnum.D.getKey();
		String dimensionName = DimensionEnum.D.getValue();
		List<MonitorConfigDetailDto> monitorConfigDetailList = getDetailByOrgId(orgId,hrOrgType);
		SaleVo vo = getDataSale(orgId,reportDate,monitorConfigDetailList);
		//都不为空 才往下执行
		if (StringUtils.isNotEmpty(vo.getStockRemovalRate()) && StringUtils.isNotEmpty(vo.getStockRemovalRatelongtime())) {
			//库存去化率 
			List<MonitorConfigDetailDto>arList=monitorConfigDetailList.stream()
					.filter(x->x.getTargetCode().equals(TargetNameEnum.I.getKey())).collect(Collectors.toList());
			//长期库存去化率
			List<MonitorConfigDetailDto>brList=monitorConfigDetailList.stream()
					.filter(x->x.getTargetCode().equals(TargetNameEnum.J.getKey())).collect(Collectors.toList());
			// 是否满足预警条件
			String arStatus = Constants.NONE;
			String brStatus = Constants.NONE;
			
			if(StringUtils.isNotEmpty(vo.getStockRemovalRate())) {
				arStatus = getStatus(arList, Double.parseDouble(vo.getStockRemovalRate()));
			}
			if(StringUtils.isNotEmpty(vo.getStockRemovalRatelongtime())) {
				brStatus = getStatus(brList, Double.parseDouble(vo.getStockRemovalRatelongtime()));
			}

			//判断所有条件是否都满足 预警标准
			if (!arStatus.equals(Constants.NONE) && !brStatus.equals(Constants.NONE) 
					&& arStatus.equals(Constants.WARNING) && brStatus.equals(Constants.WARNING)) {
					//预警条件
					String condition=getEarlyWarningConditions(hrOrgType,orgId, dimensionCode, reportDate);
					
					// ×× 库存去化率/长期库存去化率均达到预警值，其中库存去化率×，长期库存去华率×，请知悉
					String targetNames = TargetNameEnum.I.getValue() + vo.getStockRemovalRate() + ","
							+ TargetNameEnum.J.getValue() + vo.getStockRemovalRatelongtime() + ","
							+ Constants.PLEASE_KNOW;
					String content = orgName +TargetNameEnum.I.getValue()+"/"
							+TargetNameEnum.J.getValue()+ Constants.ALL_REACH_THE_WARNING_VALUE
							+ targetNames;
					
					String orgType=null;
					String parentId= null;
					if(StrUtils.isNotEmpty(projectId) && StrUtils.isNotEmpty(cityId) && StrUtils.isNotEmpty(regionId) && StrUtils.isNotEmpty(groupId)) {
						parentId = cityId;
						orgType = TodoOrgTypeEnum.FOUR.getValue();		
					}else if(StrUtils.isEmpty(projectId) && StrUtils.isNotEmpty(cityId) && StrUtils.isNotEmpty(regionId) && StrUtils.isNotEmpty(groupId)) {
						parentId = regionId;
						orgType = TodoOrgTypeEnum.THREE.getValue();		
					}else if(StrUtils.isEmpty(projectId) && StrUtils.isEmpty(cityId) && StrUtils.isNotEmpty(regionId) && StrUtils.isNotEmpty(groupId)) {
						parentId = groupId;
						orgType = TodoOrgTypeEnum.TWO.getValue();		
					}else if(StrUtils.isEmpty(projectId) && StrUtils.isEmpty(cityId) && StrUtils.isEmpty(regionId) && StrUtils.isNotEmpty(groupId)) {
						orgType = TodoOrgTypeEnum.ONE.getValue();		
					}
					
					insertMonitorWarningLog(reportDate,groupId,regionId,cityId,projectId,parentId,null,orgId,orgName,orgType,dimensionCode, dimensionName,condition, content,userList,monitorWarningLogList);
					
//					sendWarning(groupId,regionId, cityId, projectId,todoOrgType, dimensionCode,dimensionName,condition,reportDate,content,userList);
			}
		}
	}
	
	
	
	/**
	 * 存-验证是否发送门户待办
	 */
	public void verifyStockWhetherTosend(String groupId,String regionId,String cityId,String projectId,
			String todoOrgType,String reportDate,String hrOrgType,String orgId,String orgName,
			List<IdmUser> userList,List<MonitorWarningLog> monitorWarningLogList) {
		String dimensionCode = DimensionEnum.E.getKey();
		String dimensionName = DimensionEnum.E.getValue();
		List<MonitorConfigDetailDto> monitorConfigDetailList = getDetailByOrgId(orgId,hrOrgType);
		StockVo vo=getDataStock (orgId,reportDate,monitorConfigDetailList);
		//都不为空 才往下执行
		if (StringUtils.isNotEmpty(vo.getStoreSaleRate())
				&& StringUtils.isNotEmpty(vo.getStoreRatelongTime())
				&& StringUtils.isNotEmpty(vo.getStoreSaleRatelongtime())) {

			//存销比配置详情
			List<MonitorConfigDetailDto>lList=monitorConfigDetailList.stream()
					.filter(x->x.getTargetCode().equals(TargetNameEnum.L.getKey())).collect(Collectors.toList());
			//长期库存占比(百分比) 配置详情
			List<MonitorConfigDetailDto>mList=monitorConfigDetailList.stream()
					.filter(x->x.getTargetCode().equals(TargetNameEnum.M.getKey())).collect(Collectors.toList());
			//长期库存存销比配置详情
			List<MonitorConfigDetailDto>oList=monitorConfigDetailList.stream()
					.filter(x->x.getTargetCode().equals(TargetNameEnum.O.getKey())).collect(Collectors.toList());
			
			// 是否满足预警条件
			String aStatus = Constants.NONE;
			String bStatus = Constants.NONE;
			String cStatus = Constants.NONE;
			
			if(StringUtils.isNotEmpty(vo.getStoreSaleRate())) {
				aStatus = getStatus(lList, Double.parseDouble(vo.getStoreSaleRate()));
			}
			if(StringUtils.isNotEmpty(vo.getStoreRatelongTime())) {
				bStatus = getStatus(mList, Double.parseDouble(vo.getStoreRatelongTime()));
			}
			if(StringUtils.isNotEmpty(vo.getStoreSaleRatelongtime())) {
				cStatus = getStatus(oList, Double.parseDouble(vo.getStoreSaleRatelongtime()));
			}

			//判断所有条件是否都满足 预警标准
			if (!aStatus.equals(Constants.NONE) && !bStatus.equals(Constants.NONE) && !cStatus.equals(Constants.NONE) ) {
				if(aStatus.equals(Constants.WARNING) && bStatus.equals(Constants.WARNING)
						&& cStatus.equals(Constants.WARNING)) {
					//预警条件
					String condition=getEarlyWarningConditions(hrOrgType,orgId, dimensionCode, reportDate);
					//长期库存占比vo.getStoreRatelongTime()
					//长期库存(亿元)
					double storeLongTimeDouble=StrUtils.divideBillion(new BigDecimal(vo.getStoreLongTime()));
					//集团总体存销比/长期库存存销比/长期库存均达到预警值，其中存销比×，长期库存存销比×，长期库存×亿，请知悉
					//长期库存占比去掉提示,改为长期库存×亿
					String targetNames = TargetNameEnum.L.getValue() + vo.getStoreSaleRate() + ","
							+ TargetNameEnum.O.getValue() + vo.getStoreSaleRatelongtime() + ","
							+ Constants.LONG_TERM_INVENTORY + storeLongTimeDouble + "亿,"
							+ Constants.PLEASE_KNOW;
					String content = orgName +TargetNameEnum.L.getValue()+"/"
							+ TargetNameEnum.O.getValue()+"/"
							+ Constants.LONG_TERM_INVENTORY
							+ Constants.ALL_REACH_THE_WARNING_VALUE
							+ targetNames;
					
					String orgType=null;
					String parentId= null;
					if(StrUtils.isNotEmpty(projectId) && StrUtils.isNotEmpty(cityId) && StrUtils.isNotEmpty(regionId) && StrUtils.isNotEmpty(groupId)) {
						parentId = cityId;
						orgType = TodoOrgTypeEnum.FOUR.getValue();		
					}else if(StrUtils.isEmpty(projectId) && StrUtils.isNotEmpty(cityId) && StrUtils.isNotEmpty(regionId) && StrUtils.isNotEmpty(groupId)) {
						parentId = regionId;
						orgType = TodoOrgTypeEnum.THREE.getValue();		
					}else if(StrUtils.isEmpty(projectId) && StrUtils.isEmpty(cityId) && StrUtils.isNotEmpty(regionId) && StrUtils.isNotEmpty(groupId)) {
						parentId = groupId;
						orgType = TodoOrgTypeEnum.TWO.getValue();		
					}else if(StrUtils.isEmpty(projectId) && StrUtils.isEmpty(cityId) && StrUtils.isEmpty(regionId) && StrUtils.isNotEmpty(groupId)) {
						orgType = TodoOrgTypeEnum.ONE.getValue();		
					}
					
					insertMonitorWarningLog(reportDate,groupId,regionId,cityId,projectId,parentId,null,orgId,orgName,orgType,dimensionCode, dimensionName,condition, content,userList,monitorWarningLogList);

//					sendWarning(groupId,regionId, cityId, projectId,todoOrgType, dimensionCode,dimensionName,condition,reportDate,content,userList);
				}
			}
		}
	}
	
	
	/**
	 * 结-验证是否发送门户待办
	 */
	public void verifyStatementWhetherTosend(String groupId,String regionId,String cityId,String projectId,
			String todoOrgType,String reportDate,String hrOrgType,String orgId,String orgName,List<IdmUser> userList,List<MonitorWarningLog> monitorWarningLogList) {
		String dimensionCode = DimensionEnum.F.getKey();
		String dimensionName = DimensionEnum.F.getValue();
		List<MonitorConfigDetailDto> monitorConfigDetailList = getDetailByOrgId(orgId,hrOrgType);
		StatementVo vo = getDataStatement(orgId,reportDate,monitorConfigDetailList);
		//都不为空 才往下执行
		if (StringUtils.isNotEmpty(vo.getStatementRate())) {
			//结转去化率 配置详情
			List<MonitorConfigDetailDto> qList = new ArrayList<>();
			//截取月份
			String month=reportDate.substring(4,6);
			// 结转去化率 1-6月取上半年
			String content=""; 
			if(Integer.parseInt(month) <= Constants.SIX) {
				qList = monitorConfigDetailList.stream()
						.filter(x -> x.getTargetCode().equals(TargetNameEnum.Q.getKey()))
						.collect(Collectors.toList());
				content = orgName + Constants.FIRST_HALF_YEAR + vo.getStatementRate() + Constants.PLEASE_KNOW;
			}
			// 结转去化率 7-12取下半年
			if(Integer.parseInt(month) >= Constants.SEVEN) {
				qList = monitorConfigDetailList.stream()
						.filter(x -> x.getTargetCode().equals(TargetNameEnum.R.getKey()))
						.collect(Collectors.toList());
				content = orgName + Constants.LOWER_HALF_YEAR + vo.getStatementRate() + Constants.PLEASE_KNOW;
			}
			// 是否满足预警条件
			String aStatus = Constants.NONE;
			if(StringUtils.isNotEmpty(vo.getStatementRate())) {
				aStatus = getStatus(qList, Double.parseDouble(vo.getStatementRate()));
			}
			
			//判断所有条件是否都满足 预警标准
			if (!aStatus.equals(Constants.NONE) && aStatus.equals(Constants.WARNING)) {
				//预警条件
				String condition=getEarlyWarningConditions(hrOrgType,orgId, dimensionCode, reportDate);
				
				String orgType=null;
				String parentId= null;
				if(StrUtils.isNotEmpty(projectId) && StrUtils.isNotEmpty(cityId) && StrUtils.isNotEmpty(regionId) && StrUtils.isNotEmpty(groupId)) {
					parentId = cityId;
					orgType = TodoOrgTypeEnum.FOUR.getValue();		
				}else if(StrUtils.isEmpty(projectId) && StrUtils.isNotEmpty(cityId) && StrUtils.isNotEmpty(regionId) && StrUtils.isNotEmpty(groupId)) {
					parentId = regionId;
					orgType = TodoOrgTypeEnum.THREE.getValue();		
				}else if(StrUtils.isEmpty(projectId) && StrUtils.isEmpty(cityId) && StrUtils.isNotEmpty(regionId) && StrUtils.isNotEmpty(groupId)) {
					parentId = groupId;
					orgType = TodoOrgTypeEnum.TWO.getValue();		
				}else if(StrUtils.isEmpty(projectId) && StrUtils.isEmpty(cityId) && StrUtils.isEmpty(regionId) && StrUtils.isNotEmpty(groupId)) {
					orgType = TodoOrgTypeEnum.ONE.getValue();		
				}
				
				insertMonitorWarningLog(reportDate,groupId,regionId,cityId,projectId,parentId,null,orgId,orgName,orgType,dimensionCode, dimensionName,condition, content,userList,monitorWarningLogList);

//				sendWarning(groupId,regionId, cityId, projectId,todoOrgType, dimensionCode,dimensionName,condition,reportDate,content,userList);
			}
		}
	}
	
	
	
	/**
	 * 产-验证是否发送门户待办
	 */
	public void verifyProduceWhetherTosend(String groupId,String regionId,String cityId,String projectId,
			String todoOrgType,String reportDate,String hrOrgType,String orgId,String orgName,List<IdmUser> userList,List<MonitorWarningLog> monitorWarningLogList) {
		String dimensionCode = DimensionEnum.B.getKey();
		String dimensionName = DimensionEnum.B.getValue();
		List<MonitorConfigDetailDto> monitorConfigDetailList = getDetailByOrgId(orgId,hrOrgType);
		ProduceVo vo = getDataProduce(orgId,reportDate,monitorConfigDetailList);
		//都不为空 才往下执行
		if (StringUtils.isNotEmpty(vo.getFirstOpenOvhdRate()) && StringUtils.isNotEmpty(vo.getRenewalInTransitRate())) {
			//首开项目开销比配置详情
			List<MonitorConfigDetailDto>cList=monitorConfigDetailList.stream()
					.filter(x->x.getTargetCode().equals(TargetNameEnum.C.getKey())).collect(Collectors.toList());
			//续销项目在途比配置详情
			List<MonitorConfigDetailDto>dList=monitorConfigDetailList.stream()
					.filter(x->x.getTargetCode().equals(TargetNameEnum.D.getKey())).collect(Collectors.toList());
			
			// 是否满足预警条件
			String arStatus = Constants.NONE;
			String brStatus = Constants.NONE;
			if(StringUtils.isNotEmpty(vo.getFirstOpenOvhdRate())) {
				arStatus = getStatus(cList, Double.parseDouble(vo.getFirstOpenOvhdRate()));
			}
			if(StringUtils.isNotEmpty(vo.getRenewalInTransitRate())) {
				brStatus = getStatus(dList, Double.parseDouble(vo.getRenewalInTransitRate()));
			}
			if(todoOrgType.equals(TodoOrgTypeEnum.FOUR.getKey())) {
				if (!arStatus.equals(Constants.NONE) || !brStatus.equals(Constants.NONE)) {
					if(arStatus.equals(Constants.WARNING) && brStatus.equals(Constants.WARNING)) {
						//判断所有条件是否都满足 预警标准
						//预警条件
						String condition=getEarlyWarningConditions(hrOrgType,orgId, dimensionCode, reportDate);
						
						// 集团总体开销比/在途比均达到预警值，其中开销比×，在途比×，请知悉
						String targetNames = TargetNameEnum.C.getValue() + vo.getFirstOpenOvhdRate() + ","
								+ TargetNameEnum.D.getValue() + vo.getRenewalInTransitRate() + ","
								+ Constants.PLEASE_KNOW;
						String content = orgName +TargetNameEnum.C.getValue()+"/"
								+TargetNameEnum.D.getValue()+ Constants.ALL_REACH_THE_WARNING_VALUE
								+ targetNames;
						
						insertMonitorWarningLog(reportDate,groupId,regionId,cityId,projectId,cityId,null,projectId,orgName,TodoOrgTypeEnum.FOUR.getValue(),dimensionCode, dimensionName,condition, content,userList,monitorWarningLogList);
						// 开始发送
//						sendWarning(groupId,regionId, cityId, projectId,todoOrgType, dimensionCode,dimensionName,condition,reportDate,content,userList);
					}
				}
			}else {
				//判断所有条件是否都满足 预警标准
				if (!arStatus.equals(Constants.NONE) && !brStatus.equals(Constants.NONE) &&
						arStatus.equals(Constants.WARNING) && brStatus.equals(Constants.WARNING)) {
						//预警条件
						String condition=getEarlyWarningConditions(hrOrgType,orgId, dimensionCode, reportDate);
						
						// 集团总体开销比/在途比均达到预警值，其中开销比×，在途比×，请知悉
						String targetNames = TargetNameEnum.C.getValue() + vo.getFirstOpenOvhdRate() + ","
								+ TargetNameEnum.D.getValue() + vo.getRenewalInTransitRate() + ","
								+ Constants.PLEASE_KNOW;
						String content = orgName +TargetNameEnum.C.getValue()+"/"
								+TargetNameEnum.D.getValue()+ Constants.ALL_REACH_THE_WARNING_VALUE
								+ targetNames;
						
						String orgType=null;
						String parentId= null;
						if(StrUtils.isEmpty(projectId) && StrUtils.isNotEmpty(cityId) && StrUtils.isNotEmpty(regionId) && StrUtils.isNotEmpty(groupId)) {
							parentId = regionId;
							orgType = TodoOrgTypeEnum.THREE.getValue();		
						}else if(StrUtils.isEmpty(projectId) && StrUtils.isEmpty(cityId) && StrUtils.isNotEmpty(regionId) && StrUtils.isNotEmpty(groupId)) {
							parentId = groupId;
							orgType = TodoOrgTypeEnum.TWO.getValue();		
						}else if(StrUtils.isEmpty(projectId) && StrUtils.isEmpty(cityId) && StrUtils.isEmpty(regionId) && StrUtils.isNotEmpty(groupId)) {
							orgType = TodoOrgTypeEnum.ONE.getValue();		
						}
						
						insertMonitorWarningLog(reportDate,groupId,regionId,cityId,projectId,parentId,null,orgId,orgName,orgType,dimensionCode, dimensionName, condition,content,userList,monitorWarningLogList);
						
//						sendWarning(groupId,regionId, cityId, projectId,todoOrgType, dimensionCode,dimensionName,condition,reportDate,content,userList);
				}
			}	
		}
	}
	
	
	
	/**
	 * 封装一个没有状态的组织和圆点vo
	 * @param orgName
	 * @param orgId1
	 * @param value BigDecimal
	 * @param hrOrgTypeId
	 * @return
	 */
	public OrgRoundVo getOrgRoundBigDecimalNoStatus(String orgName,String orgId1
			,BigDecimal value,String hrOrgTypeId) {
		OrgRoundVo vo=new OrgRoundVo();
		vo.setOrgName(orgName);
		//圆点状态(warning-预警标准-红色,remind-提醒标准-黄色,health-健康标准-绿色)
		vo.setResourceStatus(Constants.NONE);
		vo.setQuotaVal(value == null ? BigDecimal.ZERO : value);
		vo.setOrgId(orgId1);
		vo.setOrgType(hrOrgTypeId);
		vo.setGroup(Constants.ZERO);
		return vo;
	}
	
	
	/**
	 * 封装一个有状态的组织和圆点vo
	 * @param orgName
	 * @param list
	 * @param orgId1
	 * @param value
	 * @param hrOrgTypeId
	 * @return
	 */
	public OrgRoundVo getOrgRoundBigDecimalStatus(String orgName,List<MonitorConfigDetailDto>list,String orgId1
			,BigDecimal value,String hrOrgTypeId) {
		OrgRoundVo vo=new OrgRoundVo();
		vo.setOrgName(orgName);
		String status=Constants.NONE;
		vo.setQuotaVal(BigDecimal.ZERO);
		if(value!=null) {
			//BigDecimal除以1个亿转成double
			double dv=StrUtils.divideBillion(value);
			//圆点状态(warning-预警标准-红色,remind-提醒标准-黄色,health-健康标准-绿色 none没有状态)
			status=getStatus(list,dv);
			vo.setQuotaVal(value);
		}
		vo.setResourceStatus(status);
		vo.setOrgId(orgId1);
		vo.setOrgType(hrOrgTypeId);
		vo.setGroup(StrUtils.getStatusGroup(status));
		return vo;
	}
	
	/**
	 * 获取多个岗位组的用户信息
	 * @param positionGroupIds
	 * @param orgId
	 * @param groupHeadquartersId 集团总部id
	 * @return
	 */
	public List<IdmUser> getPositionGroupsUserListV2(List<String>positionGroupIds,String orgId,String prevOrgId,String groupHeadId) {
		HashSet<IdmUser>userList=new HashSet<>();
		for (String string : positionGroupIds) {
			//本级部门查询出来
			List<IdmUser> orgUserList = idmUserService.getPositionGroupUserList(string, orgId);
//			if(StringUtils.isNotEmpty(prevOrgId)) {
////				//上级部门查询出来
////				List<IdmUser> prevUserList = idmUserService.getPositionGroupUserList(string, prevOrgId);
////				userList.addAll(prevUserList);
////			}
//			if(StringUtils.isNotEmpty(groupHeadId)) {
//				//集团总部的人一块查询出来
//				List<IdmUser> groupUserList = idmUserService.getPositionGroupUserList(string, groupHeadId);
//				userList.addAll(groupUserList);
//			}
			userList.addAll(orgUserList);
		}
		List<IdmUser>newUserList=new ArrayList<>();
		if(CollectionUtils.isNotEmpty(userList)) {
			for (IdmUser idmUser : userList) {
				newUserList.add(idmUser);
			}
		}
		return newUserList;
	}


}
